Categorygithub.com/checkly/checkly-go-sdk
modulepackage
1.10.0
Repository: https://github.com/checkly/checkly-go-sdk.git
Documentation: pkg.go.dev

# README

Checkly Go SDK

Contributor Covenant Tests GoDoc Go Report Card GitHub go.mod Go version GitHub tag (latest by date)

This project is a Go SDK for Checkly monitoring service. It allows you to handle your checks, check groups, snippets, environments variables and everything you can do with our REST API.

Installation

To use the client library with your Checkly account, you will need an API Key for the account. Go to the Account Settings: API Keys page and click 'Create API Key'.

Make sure your project is using Go Modules (it will have a go.mod file in its root if it already is):

$ go mod init

Then, add the reference of checkly-go-sdk in a Go program using import:

import checkly "github.com/checkly/checkly-go-sdk"

Run any of the normal go commands (build/install/test) and the Go toolchain will resolve and fetch the checkly-go-sdk module automatically.

Alternatively, you can also explicitly go get the package into a project:

$ go get -u github.com/checkly/checkly-go-sdk

Getting Started

Create a new checkly Client by calling checkly.NewClient() (you will need to set your Checkly API Key and Account ID)

baseUrl := "https://api.checklyhq.com"
apiKey := os.Getenv("CHECKLY_API_KEY")
accountId := os.Getenv("CHECKLY_ACCOUNT_ID")

client := checkly.NewClient(
	baseUrl,
	apiKey,
	nil, //custom http client, defaults to http.DefaultClient
	nil, //io.Writer to output debug messages
)

client.SetAccountId(accountId)

Note: if you don't have an API key, you can create one at here

Create your first checks

Once you have a client, you can create a check. See here how to create your first API & Browser checks.

apiCheck := checkly.Check{
	Name:                 "My API Check",
	Type:                 checkly.TypeAPI,
	Frequency:            5,
	Activated:            true,
	Locations: []string{
		"eu-west-1",
		"ap-northeast-2",
	},
	Tags: []string{ "production" },
	Request: checkly.Request{
		Method: http.MethodGet,
		URL:    "https://api.checklyhq.com/v1",
	},
}

browserCheck := checkly.Check{
	Name:          "My Browser Check",
	Type:          checkly.TypeBrowser,
	Frequency:     5,
	Activated:     true,
	Locations:     []string{"eu-west-1"},
	Script: `const assert = require("chai").assert;
	const puppeteer = require("puppeteer");

	const browser = await puppeteer.launch();
	const page = await browser.newPage();
	await page.goto("https://example.com");
	const title = await page.title();

	assert.equal(title, "Example Site");
	await browser.close();`,
}

ctx := context.WithTimeout(context.Background(), time.Second * 5)
client.CreateCheck(ctx, apiCheck)
client.CreateCheck(ctx, browserCheck)

A complete example program! You can see an example program which creates a Checkly check in the demo folder.

Questions

For questions and support please open a new discussion. The issue list of this repo is exclusively for bug reports and feature/docs requests.

Issues

Please make sure to respect issue requirements and choose the proper issue template when opening an issue. Issues not conforming to the guidelines may be closed.

Contribution

Please make sure to read the Contributing Guide before making a pull request.

License

MIT

# Functions

AlertChannelConfigFromJSON gets AlertChannel.config from JSON.
NewClient constructs a Checkly API client.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Contains asserts that the source contains a specified value.
Equals asserts that the source and target are equal.
GreaterThan asserts that the source is greater than the target.
Headers identifies the HTTP headers as an assertion source.
IsEmpty asserts that the source is empty.
JSONBody identifies the JSON body data as an assertion source.
LessThan asserts that the source is less than the target.
NotContains asserts that the source does not contain a specified value.
NotEmpty asserts that the source is not empty.
NotEquals asserts that the source and target are not equal.
ResponseData identifies the response data of a TCP check as an assertion source.
ResponseTime identifies the response time as an assertion source.
RunBased identifies a run-based escalation type, for use with an AlertSettings.
StatusCode identifies the HTTP status code as an assertion source.
TextBody identifies the response body text as an assertion source.
TimeBased identifies a time-based escalation type, for use with an AlertSettings.
TypeAPI is used to identify an API check.
TypeBrowser is used to identify a browser check.
TypeHeartbeat is used to identify a browser check.

# Structs

AlertChannel represents an alert channel and its subscribed checks.
AlertChannelCALL defines a type for a phone call alert channel.
AlertChannelEmail defines a type for an email alert channel.
AlertChannelOpsgenie defines a type for an opsgenie alert channel.
AlertChannelPagerduty defines a type for an pager duty alert channel.
AlertChannelSlack defines a type for a slack alert channel.
AlertChannelSMS defines a type for a sms alert channel.
AlertChannelSubscription represents a subscription to an alert channel.
AlertChannelWebhook defines a type for a webhook alert channel.
AlertSettings represents an alert configuration.
APICheckDefaults represents the default settings for API checks within a given group.
Assertion represents an assertion about an API response, which will be verified as part of the check.
BasicAuth represents the HTTP basic authentication credentials for a request.
Check represents the parameters for an existing check.
CheckResult represents a Check result.
CheckResultsFilter represents the parameters that can be passed while getting Check Results.
No description provided by the author
Dashboard defines a type for a dashboard.
DashboardKey represents the keys that the dashboard has.
EnvironmentVariable represents a key-value pair for setting environment values during check execution.
Group represents a check group.
Heartbeat represents the parameter for the heartbeat check.
No description provided by the author
KeyValue represents a key-value pair, for example a request header setting, or a query parameter.
No description provided by the author
MaintenanceWindow defines a type for a maintenance window.
Check represents the parameters for an existing check.
ParallelRunFailureThreshold represent an alert escalation based on the number of failing regions, only applicable for parallel checks.
PrivateLocation defines a type for a private location.
PrivateLocationKey represents the keys that the private location has.
Reminders represents the number of reminders to send after an alert notification, and the time interval between them.
Request represents the parameters for the request made by the check.
No description provided by the author
RunBasedEscalation represents an alert escalation based on a number of failed check runs.
No description provided by the author
Snippet defines Snippet type.
Deprecated: this type will be removed in future versions.
This type is used to describe Checkly's official public range of IP addresses checks are executed from see https://www.checklyhq.com/docs/monitoring/allowlisting/#ip-range-allowlisting.
TCPCheck represents a TCP check.
TCPRequest represents the parameters for a TCP check's connection.
TimeBasedEscalation represents an alert escalation based on the number of minutes after a check first starts failing.
Trigger defines a type for a check trigger.
Trigger defines a type for a group trigger.

# Interfaces

Client is an interface that implements Checkly's API.

# Type aliases

ApiCheckResult represents an API Check result.
BrowserCheckResult represents a Browser Check result.
Check type constants.