internalserver

package
v0.0.0-...-1c9aa72 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2021 License: Apache-2.0 Imports: 7 Imported by: 20

Documentation

Overview

Example
registry := prometheus.NewRegistry()
healthchecks := healthcheck.NewMetricsHandler(healthcheck.NewHandler(), registry)

// Create the new internalserver Handler
h := NewHandler(
	WithHealthchecks(healthchecks),
	WithPrometheusRegistry(registry),
)

// Make a HTTP request against the internalserver Handler
fmt.Print(dumpRequest(h, http.MethodGet, "/"))
Output:

HTTP/1.1 200 OK
Connection: close
Content-Type: text/html; charset=utf-8

<html><head><title>Internal</title></head><body>
<h1>Internal</h1>
<p><a href='/live'>/live - Exposes liveness checks</a></p>
<p><a href='/metrics'>/metrics - Exposes Prometheus metrics</a></p>
<p><a href='/ready'>/ready - Exposes readiness checks</a></p>
</body></html>
Example (Custom_endpoint)
registry := prometheus.NewRegistry()

// Create the new internalserver Handler like normal.
h := NewHandler(
	WithPrometheusRegistry(registry),
)

// Add a custom endpoint to the internal handler also registering it with the index page.
h.AddEndpoint("/foo", "My other signal to expose internally",
	func(w http.ResponseWriter, r *http.Request) {
	},
)

// Make a HTTP request against the internalserver Handler
fmt.Print(dumpRequest(h, http.MethodGet, "/"))
Output:

HTTP/1.1 200 OK
Connection: close
Content-Type: text/html; charset=utf-8

<html><head><title>Internal</title></head><body>
<h1>Internal</h1>
<p><a href='/foo'>/foo - My other signal to expose internally</a></p>
<p><a href='/metrics'>/metrics - Exposes Prometheus metrics</a></p>
</body></html>

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	http.ServeMux
	// contains filtered or unexported fields
}

Handler is a http.ServeMux that knows about all endpoints to render a nice index page.

func NewHandler

func NewHandler(options ...Option) *Handler

NewHandler creates a new internalserver Handler.

func (*Handler) AddEndpoint

func (h *Handler) AddEndpoint(pattern string, description string, handler http.HandlerFunc)

AddEndpoint wraps HandleFunc for adding http handlers to add a meaningful description to the index page.

type Option

type Option func(h *Handler)

Option is a func that modifies the configuration for the internalserver handler.

func WithHealthchecks

func WithHealthchecks(healthchecks healthcheck.Handler) Option

WithHealthchecks adds the healthchecks endpoints /live and /ready to the internalserver.

func WithName

func WithName(name string) Option

WithName allows to set an application name for the internalserver handler.

func WithPProf

func WithPProf() Option

WithPProf adds all pprof endpoints under /debug to the internalserver.

func WithPrometheusRegistry

func WithPrometheusRegistry(registry *prometheus.Registry) Option

WithPrometheusRegistry adds a /metrics endpoint to the internalserver.

Jump to

Keyboard shortcuts

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