readysrv

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

README

Ready Server

The package core/workers/readysrv is used to provide readiness checks for a service.

Configuration

The readiness server can be configured through the environment to match setup in the infrastructure.

  • READINESS_INTERFACE default: :3674
  • READINESS_PATH default: /ready

Examples

srv := readysrv.New(readysrv.Checks{
    "google": readysrv.CheckerFunc(func() ([]string, bool) {
        if _, err := http.Get("https://google.com"); err != nil {
            return []string{err.Error()}, false
        }
        return []string{"google can be accessed"}, true
    }),
})
srv.Run(ctx, ioutil.Discard)

Documentation

Overview

Package readysrv is used to provide readiness checks for a service.

Example
package main

import (
	"context"
	"io/ioutil"
	"net/http"

	"github.com/LUSHDigital/core/workers/readysrv"
)

var ctx context.Context

func main() {
	srv := readysrv.New(readysrv.Checks{
		"google": readysrv.CheckerFunc(func() ([]string, bool) {
			if _, err := http.Get("https://google.com"); err != nil {
				return []string{err.Error()}, false
			}
			return []string{"google can be accessed"}, true
		}),
	})
	srv.Run(ctx, ioutil.Discard)
}
Output:

Index

Examples

Constants

View Source
const (
	// DefaultInterface is the port that we listen to the prometheus path on by default.
	DefaultInterface = "0.0.0.0:3674"

	// DefaultPath is the path where we expose prometheus by default.
	DefaultPath = "/ready"
)

Variables

This section is empty.

Functions

func CheckHandler

func CheckHandler(checks Checks) http.HandlerFunc

CheckHandler provides a function for providing health checks over http.

Types

type Checker

type Checker interface {
	Check() ([]string, bool)
}

Checker defines the interface for checking health of remote services.

type CheckerFunc

type CheckerFunc func() ([]string, bool)

CheckerFunc defines a single function for checking health of remote services.

func (CheckerFunc) Check

func (f CheckerFunc) Check() ([]string, bool)

Check will perform the check of the checker function.

type Checks

type Checks map[string]Checker

Checks defines a matrix of health checks to be run.

func (Checks) AddCheck

func (c Checks) AddCheck(name string, check Checker)

AddCheck will add a health check to the matrix.

type Server

type Server struct {
	Interface string
	Path      string
	Checks    Checks
}

Server defines a readiness server.

func New

func New(checks Checks) *Server

New creates a new default metrics server.

func (*Server) Run

func (s *Server) Run(ctx context.Context, out io.Writer) error

Run will start the metrics server.

Jump to

Keyboard shortcuts

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