zpages

package module
v0.0.0-...-83491a4 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2019 License: MIT Imports: 11 Imported by: 0

README

zpages

MIT licensed GoDoc Build Status Coverage Status Go Report Card

Go utilities for generating helpful debug and internal pages for server inspection. Works out of the box with net/http based web servers.

Installation

go get -u github.com/awbraunstein/zpages

Usage

Just add the handlers/middleware that you want and run your server. It is recommended to put these pages behind some sort of internal auth to avoid leaking this information to users.

func main() {
	mux := http.NewServeMux()
	requestzHandler, err := zpages.NewRequestz()
	if err != nil {
		log.Fatalf("Unable to initialize Requestz handler; err=%v", err)
	}
	mux.Handle("/healthz", requestzHandler.Middleware(zpages.NewHealthz()))
	statuszHandler, err := zpages.NewStatusz()
	if err != nil {
		log.Fatalf("Unable to initialize Statusz handler; err=%v", err)
	}
	mux.Handle("/statusz", requestzHandler.Middleware(statuszHandler))
	mux.Handle("/requestz", requestzHandler.Middleware(requestzHandler))
	log.Println("Listening on %s...", *httpAddr)
	http.ListenAndServe(":8080", mux)
}

Documentation

Overview

Package zpages contains utilties for creating internal/debug pages to be served by a standard net/http server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Healthz

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

Healthz renders a page that displays a health check value. By default, this handler will render ok when the server is ready to serve. It will echo the healthString url param if it is provided. Use NewHealthz() to construct this struct.

func NewHealthz

func NewHealthz(okValue ...string) *Healthz

NewHealthz creates a new Healthz http handler. This method accepts either 0 or 1 params and will panic on any other number of values.

NewHealthz()

or

NewHealthz("ok")

func (*Healthz) ServeHTTP

func (h *Healthz) ServeHTTP(resp http.ResponseWriter, req *http.Request)

type RequestInfo

type RequestInfo struct {
	// The time that the request was written into the store.
	Timestamp time.Time
	// The total time that it took to respond.
	Duration time.Duration
	// The http response status code.
	Status  int
	Request *http.Request
}

RequestInfo holds the information of a single request.

type Requestz

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

Requestz is an http handler that renders the requestz page.

func NewRequestz

func NewRequestz(additionalDataFns ...func(*RequestInfo)) (*Requestz, error)

NewRequestz creates a new Requestz handler. Additional functions can modify the current request's RequestInfo and are run in order.

func (*Requestz) Middleware

func (h *Requestz) Middleware(next http.Handler) http.Handler

Middleware allows for easy chaning of the Middleware handler.

func (*Requestz) ServeHTTP

func (h *Requestz) ServeHTTP(resp http.ResponseWriter, req *http.Request)

type Statusz

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

Statusz is a handler that renders the statusz page.

func NewStatusz

func NewStatusz(dataAdderFns ...func(map[string]string)) (*Statusz, error)

NewStatusz creates a new Statusz handler. Passed in functions can add additional data to the rendered template.

func (*Statusz) ServeHTTP

func (h *Statusz) ServeHTTP(resp http.ResponseWriter, _ *http.Request)

Directories

Path Synopsis
Package buildinfo is a subpackage that holds information about the current binary.
Package buildinfo is a subpackage that holds information about the current binary.
examples
chi
gin

Jump to

Keyboard shortcuts

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