Skip to content

Latest commit

 

History

History
63 lines (46 loc) · 2.04 KB

README.md

File metadata and controls

63 lines (46 loc) · 2.04 KB

Healthcheck for go applications

Go Reference License Build Status Go Report Card CodeCov

This tools allow you to unlock the kubernetes feature Liveness and Readiness.

Features

  • Logger to log failed probes
  • Automatic, manual and background checks
  • Respond with all healthchecks status in JSON format
  • Callback for integrate with metrics or other systems
  • Integrated web server

Quickstart

go get -u github.com/kazhuravlev/healthcheck

Check an examples.

package main

import (
	"context"
	"errors"
	"math/rand"
	"time"

	"github.com/kazhuravlev/healthcheck"
)

func main() {
	ctx := context.TODO()

	// 1. Init healthcheck instance. It will store all our checks.
	hc, _ := healthcheck.New()

	// 2. Register checks that will random respond with an error.
	hc.Register(ctx, healthcheck.NewBasic("redis", time.Second, func(ctx context.Context) error {
		if rand.Float64() > 0.5 {
			return errors.New("service is not available")
		}

		return nil
	}))

	// 3. Init and run a webserver for integration with Kubernetes.
	sysServer, _ := healthcheck.NewServer(hc, healthcheck.WithPort(8080))
	_ = sysServer.Run(ctx)

	// 4. Open http://localhost:8080/ready to check the status of your system
	select {}
}