steward

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2021 License: MIT Imports: 2 Imported by: 1

README

Steward

Build Status Go Reportcard GoDoc License Release

Steward adds a drop in status endpoint with minimal effort for service health checks.

Requirements

Golang version 1.6 or higher

Installation

go get github.com/gomicro/steward

Usage

See the examples within the docs for ways to use the library.

Versioning

The library will be versioned in accordance with Semver 2.0.0. See the releases section for the latest version. Until version 1.0.0 the libary is considered to be unstable.

It is always highly recommended to vendor the version you are using.

License

See LICENSE.md for more information.

Documentation

Overview

Package steward provides a drop in way of adding a status endpoint to your services

Example (CustomResponse)

ExampleCustomResponse demonstrates how to configure a custom response

package main

import (
	"net"
	"net/http"

	"github.com/gomicro/steward"
)

// StatusResponse is the data for the status endpoint to display
type StatusResponse struct {
	Application string `json:"app"`
	Version     string `json:"version"`
	BuildTime   string `json:"buildTime"`
}

// ExampleCustomResponse demonstrates how to configure a custom response
func main() {
	steward.SetStatusResponse(&StatusResponse{Application: "Foo", Version: "1.0.0", BuildTime: "Today"})

	go http.ListenAndServe(net.JoinHostPort("0.0.0.0", "8000"), nil) //nolint:errcheck
	select {}
}
Output:

Example (Dropin)

ExampleDropin demonstrates how to start a service with steward automatically injecting a status endpoint

package main

import (
	"net"
	"net/http"

	_ "github.com/gomicro/steward"
)

var (
	host = "0.0.0.0"
	port = "8000"
)

// ExampleDropin demonstrates how to start a service with steward automatically injecting a status endpoint
func main() {
	go http.ListenAndServe(net.JoinHostPort(host, port), nil) //nolint:errcheck
	select {}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleStatus

func HandleStatus(w http.ResponseWriter, req *http.Request)

HandleStatus implements the go http handler interface to display specified status details

func SetStatusEndpoint

func SetStatusEndpoint(e string)

SetStatusEndpoint overrides the default endpoint with desired value

func SetStatusResponse

func SetStatusResponse(v interface{})

SetStatusResponse overrides the default response payload for the status endpoint

Types

This section is empty.

Jump to

Keyboard shortcuts

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