api

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2023 License: Apache-2.0 Imports: 14 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 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) 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) 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