api

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

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 New

func New(log *logp.Logger, mux *http.ServeMux, c *config.C) (*Server, error)

New creates a new API Server.

func NewFromConfig added in v0.9.0

func NewFromConfig(log *logp.Logger, mux *http.ServeMux, cfg Config) (*Server, error)

NewFromConfig creates a new API server from the given Config object.

func NewWithDefaultRoutes

func NewWithDefaultRoutes(log *logp.Logger, c *config.C, ns lookupFunc) (*Server, error)

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

func (s *Server) Addr() net.Addr

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

func (s *Server) AttachHandler(route string, h http.Handler) (err error)

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

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully drains the API server of connections by using the go net/http.Server.Shutdown function

func (*Server) Start

func (s *Server) Start()

Start starts the HTTP server and accepting new connection.

func (*Server) Stop

func (s *Server) Stop() error

Stop stops the API server and free any resource associated with the process like unix sockets.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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