Giter Site home page Giter Site logo

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

Checkly's Projects

Checkly doesnโ€™t have any public repositories yet.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.