healthchecksio

package module
v1.2.0-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2019 License: Apache-2.0 Imports: 8 Imported by: 8

README

go-healthchecksio

A go client for working with the healthchecks.io api.

Installation

go get github.com/kristofferahl/go-healthchecksio

Usage

package main

import (
	"log"
	"os"

	"github.com/kristofferahl/go-healthchecksio"
)

func main() {
	apiKey := os.Getenv("HEALTHCHECKSIO_API_KEY") // See https://healthchecks.io/docs/api/

	client := healthchecksio.NewClient(apiKey)
	check := healthchecksio.Healthcheck{
		Name: "My first test",
		Tags: "go ftw",
	}

	healthcheck, err := client.Create(check)
	if err != nil {
		log.Printf("[ERROR] error creating healthcheck: %s", err)
		os.Exit(1)
	}

	log.Printf("[DEBUG] created healthcheck: %s", healthcheck)
}

Documentation

Docs can be found at godoc.org.

Developing

Running the tests requires a valid healthchecks.io API key (See https://healthchecks.io/docs/api/). Make sure the following environment variables are set.

export HEALTHCHECKSIO_API_KEY='{your api key}'

Roadmap

  • Required fields validation

Contributing

...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	// contains filtered or unexported fields
}

APIError represents an error that occured when talkinging to the Healthchecks.io api

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) Method

func (e *APIError) Method() string

Method returns the HTTP request method

func (*APIError) Status

func (e *APIError) Status() string

Status returns the HTTP response status

func (*APIError) StatusCode

func (e *APIError) StatusCode() int

StatusCode returns the HTTP response status code

func (*APIError) URL

func (e *APIError) URL() string

URL returns the HTTP request URL

type Client

type Client struct {
	APIKey      string
	BaseURL     string
	ContentType string
	HTTPClient  *http.Client
}

Client provides access to create, read, update and delete healthchecks.io resources

func NewClient

func NewClient(apiKey string) *Client

NewClient creates a new client

func (*Client) Create

func (c *Client) Create(check Healthcheck) (*HealthcheckResponse, error)

Create creates a new healthcheck

func (*Client) Delete

func (c *Client) Delete(id string) (*HealthcheckResponse, error)

Delete deletes an existing healthcheck

func (*Client) GetAll

func (c *Client) GetAll() ([]*HealthcheckResponse, error)

GetAll returns all healthchecks

func (*Client) GetAllChannels

func (c *Client) GetAllChannels() ([]*HealthcheckChannelResponse, error)

GetAllChannels returns all channels

func (*Client) Pause

func (c *Client) Pause(id string) (*HealthcheckResponse, error)

Pause pauses monitoring on existing healthcheck

func (*Client) Update

func (c *Client) Update(id string, check Healthcheck) (*HealthcheckResponse, error)

Update updates an existing healthcheck

type Healthcheck

type Healthcheck struct {
	Channels string   `json:"channels,omitempty"`
	Grace    int      `json:"grace,omitempty"`
	Name     string   `json:"name,omitempty"`
	Schedule string   `json:"schedule,omitempty"`
	Tags     string   `json:"tags,omitempty"`
	Timeout  int      `json:"timeout,omitempty"`
	Timezone string   `json:"tz,omitempty"`
	Unique   []string `json:"unique,omitempty"`
}

Healthcheck represents a healthcheck

func (*Healthcheck) ToJSON

func (hc *Healthcheck) ToJSON() (string, error)

ToJSON returns a json representation of a healthcheck data

type HealthcheckChannelResponse

type HealthcheckChannelResponse struct {
	ID   string `json:"id,omitempty"`
	Name string `json:"name,omitempty"`
	Kind string `json:"kind,omitempty"`
}

HealthcheckChannelResponse represents a channel response of healthcheck api

func (*HealthcheckChannelResponse) String

func (hc *HealthcheckChannelResponse) String() string

func (*HealthcheckChannelResponse) ToJSON

func (hc *HealthcheckChannelResponse) ToJSON() (string, error)

ToJSON returns a json representation of a healthcheck channel

type HealthcheckResponse

type HealthcheckResponse struct {
	Channels  string `json:"channels,omitempty"`
	Grace     int    `json:"grace,omitempty"`
	LastPing  string `json:"last_ping,omitempty"`
	Name      string `json:"name,omitempty"`
	NextPing  string `json:"next_ping,omitempty"`
	PauseURL  string `json:"pause_url,omitempty"`
	Pings     int    `json:"n_pings,omitempty"`
	PingURL   string `json:"ping_url,omitempty"`
	Schedule  string `json:"schedule,omitempty"`
	Status    string `json:"status,omitempty"`
	Tags      string `json:"tags,omitempty"`
	Timeout   int    `json:"timeout,omitempty"`
	Timezone  string `json:"tz,omitempty"`
	UpdateURL string `json:"update_url,omitempty"`
}

HealthcheckResponse represents a healthcheck api response

func (*HealthcheckResponse) ID

func (hc *HealthcheckResponse) ID() string

ID returns the identifier of a healthcheck

func (*HealthcheckResponse) String

func (hc *HealthcheckResponse) String() string

func (*HealthcheckResponse) ToJSON

func (hc *HealthcheckResponse) ToJSON() (string, error)

ToJSON returns a json representation of a healthcheck

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL