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 ¶
Handler is a http.ServeMux that knows about all endpoints to render a nice index page.
func NewHandler ¶
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 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.
Click to show internal directories.
Click to hide internal directories.