readysrv

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2020 License: Apache-2.0 Imports: 8 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_ADDR default: 0.0.0.0:3674
  • READINESS_PATH default: /ready

Examples

srv := readysrv.New(nil, 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)

Documentation

Overview

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

Example
package main

import (
	"context"
	"net/http"

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

var ctx context.Context

func main() {
	srv := readysrv.New(nil, 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)
}
Output:

Index

Examples

Constants

View Source
const (
	// DefaultAddr is the port that we listen to the prometheus path on by default.
	DefaultAddr = "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 Config added in v0.21.0

type Config struct {
	Path   string
	Server *http.Server
}

Config represents the configuration for the metrics server.

type Server

type Server struct {
	Path   string
	Checks Checks
	Server *http.Server
	// contains filtered or unexported fields
}

Server defines a readiness server.

func New

func New(config *Config, checks Checks) *Server

New creates a new default metrics server.

func (*Server) Addr added in v0.21.0

func (s *Server) Addr() *net.TCPAddr

Addr will block until you have received an address for your server.

func (*Server) Halt added in v0.21.0

func (s *Server) Halt(ctx context.Context) error

Halt will attempt to gracefully shut down the server.

func (*Server) Run

func (s *Server) Run(_ context.Context) error

Run will start the ready server.

Jump to

Keyboard shortcuts

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