handler

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

package handler provides a collection of useful/built-in handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	// Handler function.
	Handler http.HandlerFunc `json:"handler" validate:"required"`

	// Method to run the `Handler`.
	Method string `json:"method" validate:"required"`

	// Path to run the `Handler`.
	Path string `json:"path" validate:"required"`
}

Handler definition.

func Liveness

func Liveness() Handler

Liveness indicates the server is up, and running. It follows the "standard" which is send `200` status code, and "OK" in the body.

func Metrics

func Metrics() Handler

Metrics serves metrics.

func New

func New(method string, path string, handler http.HandlerFunc) (Handler, error)

New is `Handler` factory.

func OK

func OK() Handler

OK replies with `200` status code, and "OK" in the body.

func Readiness

func Readiness(readinessStates ...*ReadinessDeterminer) Handler

Readiness indicates the server is up, running, and ready to work. It follows the "standard" which is send `200` status code, and "OK" in the body if it's ready, otherwise sends `503`, "Service Unavailable", and the error. Multiple readinesses determiners can be passed. In this case, only if ALL are ready, the server will be considered ready.

func Stop

func Stop() Handler

Stop allows the server to be remotely, and gracefully stopped. Optionally set the `hard` query param to `true` to immediately kill the server.

type ReadinessDeterminer

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

ReadinessDeterminer definition. It determines if `name` is ready.

func NewReadinessDeterminer

func NewReadinessDeterminer(name string) *ReadinessDeterminer

NewReadinessDeterminer is the Readiness factory.

func (*ReadinessDeterminer) GetName

func (t *ReadinessDeterminer) GetName() string

Get state name.

func (*ReadinessDeterminer) GetReadiness

func (t *ReadinessDeterminer) GetReadiness() bool

Get readiness state.

func (*ReadinessDeterminer) SetName

func (t *ReadinessDeterminer) SetName(name string)

Set state name.

func (*ReadinessDeterminer) SetReadiness

func (t *ReadinessDeterminer) SetReadiness(v bool)

Set readiness state.

Jump to

Keyboard shortcuts

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