gobernate

package module
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2021 License: MIT Imports: 11 Imported by: 0

README

Build Status

Package gobernate provides an easy HTTP Handler containing all end-points required to run a golang service in Kubernetes. This code is roughly based on: https://blog.gopheracademy.com/advent-2017/kubernetes-ready-service/

To use the gobernate package to Kubernetes enable your service simply use:

import (
	"fmt"
	"net/http"

	"github.com/SebastiaanPasterkamp/gobernate"
)

func main() {
	g := gobernate.New("8080", "example", "1.0.0", "commit-sha", "build-time")

	shutdown := g.Launch()

	g.Router.HandleFunc("/hello", func(w http.ResponseWriter, _ *http.Request) {
		fmt.Fprint(w, "Hello! Your request was processed.")
	})

	g.Ready()
	<-shutdown
}

The gobernate http service provides:

  • GET /version to return a JSON structure with the service.
  • GET /health to return http.StatusOK to indicate the (web) service is running.
  • GET /readiness to signal when the service is ready. Expects Ready() to be called before signaling http.StatusOK, and will report if the service is already shutting down.
  • GET /metrics to return Prometheus formatted metric data.

To do

  • Option to add a custom readiness callback.
  • Constructor with configuration struct.
  • Built in OpenTelemetry support.

Documentation

Overview

Package gobernate provides an easy HTTP Handler containing all end-points required to run a golang service in Kubernetes. This code is roughly based on: https://blog.gopheracademy.com/advent-2017/kubernetes-ready-service/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Gobernate

type Gobernate struct {
	// Router is the mux router, so extra end-points can be added.
	Router *mux.Router
	// contains filtered or unexported fields
}

Gobernate provides an easy HTTP Handler containing all end-points required to run a golang service in Kubernetes. This code is roughly based on: https://blog.gopheracademy.com/advent-2017/kubernetes-ready-service/

func New

func New(port, name, release, commit, buildTime string) *Gobernate

New creates a Gobernate instace with port and version info

func (*Gobernate) Launch

func (g *Gobernate) Launch() chan bool

Launch runs the gobernate service on the port, and serves the version info. Returns a shutdown channel to either block while serving, or to close to take down the service

func (*Gobernate) Ready

func (g *Gobernate) Ready()

Ready signals that the service is ready to serve. Call once all initialization has completed.

func (*Gobernate) Shutdown

func (g *Gobernate) Shutdown()

Shutdown gracefully terminates the service. Automatically called when receiving SIGINT, or SIGTERM.

func (*Gobernate) URL

func (g *Gobernate) URL() string

URL returns the address:port on which the service is listening.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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