htz: github.com/faabiosr/htz Index | Files

package htz

import "github.com/faabiosr/htz"

Package htz show the health of your app.

Example Usage

The following is a simple example using the library:

package main

import (
	"encoding/json"
	"fmt"
	"github.com/faabiosr/htz"
	"time"
)

func main() {
	checkers := []htz.Checker{
		func() *htz.Check {
			return &htz.Check{
				Name:         "some-api",
				Type:         "internal-service",
				Status:       false,
				ResponseTime: 6 * time.Second,
				Optional:     false,
				Details:      map[string]interface{}{
				    "url": "internal-service.api",
			    },
			}
		},
	}

	h := htz.New("my-app", "0.0.1", checkers...)
	res, _ := json.MarshalIndent(h.Check(), "", "  ")

	fmt.Println(string(res))
}

Using with a HTTP Server:

package main

import (
	"github.com/faabiosr/htz"
	"net/http"
	"time"
)

func main() {
	checkers := []htz.Checker{
		func() *htz.Check {
			return &htz.Check{
				Name:         "some-api",
				Status:       false,
				ResponseTime: 6 * time.Second,
				Optional:     false,
			}
		},
	}

	h := htz.New("my-app", "0.0.1", checkers...)

	http.Handle("/htz", h)

	http.ListenAndServe(":8080", nil)
}

Index

Package Files

doc.go health.go

type Check Uses

type Check struct {
    Name         string                 `json:"name"`
    Type         CheckType              `json:"type"`
    Status       bool                   `json:"status"`
    ResponseTime time.Duration          `json:"response_time"`
    Optional     bool                   `json:"optional"`
    Details      map[string]interface{} `json:"details"`
}

Check retrieves the health of service.

type CheckType Uses

type CheckType string

CheckType type.

func (CheckType) MarshalJSON Uses

func (ct CheckType) MarshalJSON() ([]byte, error)

MarshalJSON marshals CheckType instance into string.

type Checker Uses

type Checker func() *Check

Checker it's type function responsible for checking the service health.

type Health Uses

type Health struct {
    Name    string
    Version string
    // contains filtered or unexported fields
}

Health defines the healthcheck configuration.

func New Uses

func New(name, version string, checkers ...Checker) *Health

New retrieves the new instance of Health.

func (*Health) Check Uses

func (h *Health) Check() *Status

Check checks the status of services.

func (*Health) ServeHTTP Uses

func (h *Health) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServerHTTP retrieves the health status.

type Status Uses

type Status struct {
    Name    string    `json:"name"`
    Version string    `json:"version"`
    Status  bool      `json:"status"`
    Date    time.Time `json:"date"`
    Checks  []*Check  `json:"checks"`
}

Status retrieves the status of health.

Package htz imports 4 packages (graph). Updated 2019-06-17. Refresh now. Tools for package owners.