statusz

package
v0.0.0-...-8887655 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2020 License: ISC, Apache-2.0 Imports: 16 Imported by: 0

README

Statusz-like page for Go

This module adds a /debug/status handler to net/http that displays useful information for debug purposes in production.

Basic Usage

For the basic status page, just include the module.

import (
    _ "code.hackerspace.pl/hscloud/go/statusz"
)

func main() {
    http.ListenAndServe("127.0.0.1:6000", nil)
}

Adding sections

To add a section to the status page, call AddStatusSection like so:

import (
    "code.hackerspace.pl/hscloud/go/statusz"
)


func main() {
    statusz.AddStatusPart("Worker Status", function(ctx context.Context) {
        return fmt.Sprintf("%d workers alive", workerCount)
    })
    http.ListenAndServe("127.0.0.1:6000", nil)
}

For custom section templates, call AddStatusPart, which accepts a http/template fragment that will be rendered on the result of the part render function.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GitCommit      = "unknown"
	GitVersion     = "unknown"
	Builder        = "unknown"
	BuildTimestamp = "0"
	// mirko populates this
	PublicAddress = "#"

	DefaultMux = true
)

Functions

func AddStatusPart

func AddStatusPart(banner, frag string, f func(context.Context) interface{})

AddStatusPart adds a new section to status. frag is used as a subtemplate of the template used to render /debug/status, and will be executed using the value of invoking f at the time of the /debug/status request. frag is parsed and executed with the html/template package. Functions registered with AddStatusFuncs may be used in the template.

func AddStatusSection

func AddStatusSection(banner string, f func(context.Context) string)

AddStatusSection registers a function that generates extra information for /debug/status. If banner is not empty, it will be used as a header before the information. If more complex output than a simple string is required use AddStatusPart instead.

func StatusHandler

func StatusHandler(w http.ResponseWriter, r *http.Request)

Types

This section is empty.

Jump to

Keyboard shortcuts

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