Documentation ¶
Overview ¶
Package admin implements an http.Server which can be used for operations and monitoring tools. It's designed to be shipped (and ran) inside an existing Go service.
Index ¶
- func Handler() http.Handler
- type Opts
- type Server
- func (s *Server) AddHandler(path string, hf http.HandlerFunc)
- func (s *Server) AddLivenessCheck(name string, f func() error)
- func (s *Server) AddReadinessCheck(name string, f func() error)
- func (s *Server) AddVersionHandler(version string)
- func (s *Server) BindAddr() string
- func (s *Server) Listen() error
- func (s *Server) SetIdleTimeout(timeout time.Duration)
- func (s *Server) SetReadTimeout(timeout time.Duration)
- func (s *Server) SetWriteTimeout(timeout time.Duration)
- func (s *Server) Shutdown()
- func (s *Server) Subrouter(pathPrefix string) *mux.Router
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents a holder around a net/http Server which is used for admin endpoints. (i.e. metrics, healthcheck)
func New ¶ added in v0.38.0
New returns an admin.Server instance that handles Prometheus metrics and pprof requests. Callers can use ':0' to bind onto a random port and call BindAddr() for the address.
func (*Server) AddHandler ¶ added in v0.6.0
func (s *Server) AddHandler(path string, hf http.HandlerFunc)
AddHandler will append an http.HandlerFunc to the admin Server
func (*Server) AddLivenessCheck ¶ added in v0.9.0
AddLivenessCheck will register a new health check that is executed on every HTTP request of 'GET /live' against the admin server.
Every check will timeout after 10s and return a timeout error.
These checks are designed to be unhealthy only when the application has started but a dependency is unreachable or unhealthy.
func (*Server) AddReadinessCheck ¶ added in v0.9.0
AddReadinessCheck will register a new health check that is executed on every HTTP request of 'GET /ready' against the admin server.
Every check will timeout after 10s and return a timeout error.
These checks are designed to be unhealthy while the application is starting.
func (*Server) AddVersionHandler ¶ added in v0.11.0
AddVersionHandler will append 'GET /version' route returning the provided version
func (*Server) BindAddr ¶
BindAddr returns the server's bind address. This is in Go's format so :8080 is valid.
func (*Server) Listen ¶
Listen brings up the admin HTTP server. This call blocks until the server is Shutdown or panics.
func (*Server) SetIdleTimeout ¶ added in v0.38.0
func (*Server) SetReadTimeout ¶ added in v0.38.0
func (*Server) SetWriteTimeout ¶ added in v0.38.0
func (*Server) Subrouter ¶ added in v0.18.2
Subrouter creates and returns a subrouter with the specific prefix.
The returned subrouter can use middleware without impacting the parent router. For example:
svr, err := New(Opts{ Addr: ":9090", }) subRouter := svr.Subrouter("/prefix") subRouter.Use(someMiddleware) subRouter.HandleFunc("/resource", ResourceHandler)
Here, requests for "/prefix/resource" would go through someMiddleware while the liveliness and readiness routes added to the parent router by New() would not.