Documentation ¶
Index ¶
- func AddHandlerFunc(api string, h HandlerFunc) error
- type Config
- type HandlerFunc
- type Server
- func (s *Server) AddRoute(path string, handler HandlerFunc)
- func (s *Server) Addr() net.Addr
- func (s *Server) AttachHandler(route string, h http.Handler) (err error)
- func (s *Server) AttachPprof()
- func (s *Server) Shutdown(ctx context.Context) error
- func (s *Server) Start()
- func (s *Server) Stop() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddHandlerFunc ¶
func AddHandlerFunc(api string, h HandlerFunc) error
AddHandlerFunc adds a handler to the global handler map. Callbacks should be added before calling NewWithDefaultRoutes() This is NOT threadsafe
Types ¶
type Config ¶
type Config struct { Enabled bool `config:"enabled"` Host string `config:"host"` Port int `config:"port"` User string `config:"named_pipe.user"` SecurityDescriptor string `config:"named_pipe.security_descriptor"` Timeout time.Duration `config:"timeout"` }
Config is the configuration for the API endpoint.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig is the default configuration used by the API endpoint.
type HandlerFunc ¶ added in v0.3.5
type HandlerFunc func(http.ResponseWriter, *http.Request)
HandlerFunc is an http callback
func MakeAPIHandler ¶ added in v0.3.5
func MakeAPIHandler(ns *monitoring.Namespace) HandlerFunc
MakeAPIHandler creates an API handler for the given namespace
func MakeRootAPIHandler ¶ added in v0.3.5
func MakeRootAPIHandler(handler HandlerFunc) HandlerFunc
MakeRootAPIHandler creates a HandlerFunc for the root / path
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server takes cares of correctly starting the HTTP component of the API and will answers all the routes defined in the received ServeMux.
func NewFromConfig ¶ added in v0.9.0
NewFromConfig creates a new API server from the given Config object.
func NewWithDefaultRoutes ¶
NewWithDefaultRoutes creates a new server with default API routes.
func (*Server) AddRoute ¶ added in v0.3.5
func (s *Server) AddRoute(path string, handler HandlerFunc)
AddRoute adds a route to the server mux
func (*Server) Addr ¶ added in v0.9.1
Addr returns the network address of the server This is useful for tests, where we usually pass the port as `0` to get allocated a random free port
func (*Server) AttachHandler ¶
AttachHandler will attach a handler at the specified route and return an error instead of panicing.
func (*Server) AttachPprof ¶
func (s *Server) AttachPprof()
AttachPprof adds /debug/pprof endpoints to the server
func (*Server) Shutdown ¶ added in v0.7.3
Shutdown gracefully drains the API server of connections by using the go net/http.Server.Shutdown function