server

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MetricsLabels = []string{
	metricsComponentLabel,
	metricsVersionLabel,
	metricsMethodLabel,
	metricsPathLabel,
	metricsCodeLabel,
}

MetricsLabels - Array of labels added to metrics:

View Source
var MetricsNames = []string{
	requestCount,
	requestDuration,
}

MetricsNames - Array of Names of the metrics:

View Source
var PathVarSub = "-"

PathVarSub replaces path variables to a same character

Functions

func CompressMiddleware added in v0.3.1

func CompressMiddleware(next http.Handler) http.Handler

CompressMiddleware gzip-encodes the response body when the client indicates support for it via the Accept-Encoding header.

func MetricsMiddleware

func MetricsMiddleware(handler http.Handler) http.Handler

MetricsMiddleware creates a new handler that collects metrics for the requests processed by the given handler.

func RegisterEntityRoutes added in v0.3.1

func RegisterEntityRoutes(
	router *Router,
	resourceService services.ResourceService,
	adapterStatusService services.AdapterStatusService,
	schemaValidator *validators.SchemaValidator,
)

RegisterEntityRoutes creates handlers and registers routes for every entity descriptor in the registry. Called at startup after config-driven descriptors have been loaded via registry.LoadDescriptors.

Top-level entities get routes at /{plural}. Child entities (ParentKind != "") get nested routes under /{parent_plural}/{parent_id}/{plural} plus flat read/update/delete access at /{plural} (POST rejected - needs parent context). All entities get /{id}/statuses sub-routes for adapter status reporting.

The kind-agnostic /resources root endpoint is registered separately.

func ResetMetricCollectors

func ResetMetricCollectors()

ResetMetricCollectors resets all prometheus collectors

func WithNotFoundHandler added in v0.3.1

func WithNotFoundHandler(mux *http.ServeMux) http.Handler

WithNotFoundHandler wraps mux so that requests matching no registered pattern get api.SendNotFound's JSON body instead of net/http's default plain-text 404.

It must NOT be implemented by registering a catch-all "/" pattern on mux: net/http.ServeMux falls back to any matching less-specific pattern (like "/") when a request's method doesn't match a more specific one, which would silently swallow the automatic 405 Method Not Allowed responses (and their Allow header) stdlib provides for registered paths. Instead, mux.Handler is used to check ahead of time whether the request matches no pattern at all (as opposed to matching a pattern with the wrong method), and only that case is rewritten.

Types

type APIServer added in v0.3.1

type APIServer struct {
	// contains filtered or unexported fields
}

func NewAPIServer

func NewAPIServer(cfg cfg, handler http.Handler) *APIServer

func (*APIServer) Listen added in v0.3.1

func (s *APIServer) Listen() (listener net.Listener, err error)

Listen only start the listener, not the server. Useful for breaking up ListenAndServer (Start) when you require the server to be listening before continuing

func (*APIServer) Serve added in v0.3.1

func (s *APIServer) Serve(listener net.Listener)

Serve start the blocking call to Serve. Useful for breaking up ListenAndServer (Start) when you require the server to be listening before continuing

func (*APIServer) Start added in v0.3.1

func (s *APIServer) Start()

Start listening on the configured port and start the server. This is a convenience wrapper for Listen() and Serve(listener Listener)

func (*APIServer) Stop added in v0.3.1

func (s *APIServer) Stop() error

type ListenNotifier

type ListenNotifier interface {
	NotifyListening() <-chan struct{}
}

ListenNotifier is an optional interface that servers can implement to signal when they are ready to accept connections

type Middleware added in v0.3.1

type Middleware func(http.Handler) http.Handler

Middleware wraps an http.Handler to produce a new http.Handler, allowing cross-cutting behavior (logging, auth, tracing, ...) to be composed around route handlers.

type RouteRegistrar added in v0.3.1

type RouteRegistrar struct {
	Register func(*Router) error
	Name     string
}

func NewEntityRouteRegistrar added in v0.3.1

func NewEntityRouteRegistrar(
	resourceService services.ResourceService,
	adapterStatusService services.AdapterStatusService,
	schemaValidator *validators.SchemaValidator,
) RouteRegistrar

type Router added in v0.3.1

type Router struct {
	// contains filtered or unexported fields
}

Router is a thin wrapper around http.ServeMux that adds gorilla/mux-style middleware chaining (.Use()) and grouping (.Group()) on top of Go's stdlib method-prefixed routing patterns (e.g. "GET /clusters/{id}").

Groups can carry a path prefix (via Group("/v1")) that is automatically prepended to every pattern registered through that group, so route handlers only declare their own path suffix.

Middlewares registered via Use() are captured at HandleFunc/Handle time, so Use() must be called before registering the routes it should apply to.

func NewRouter added in v0.3.1

func NewRouter() *Router

NewRouter creates a new top-level Router backed by a fresh http.ServeMux.

func NewRouterFromConfig added in v0.3.1

func NewRouterFromConfig(
	mainMiddleware []Middleware,
	apiMiddleware []Middleware,
	protectedAPIMiddleware []Middleware,
	authMiddleware []Middleware,
	registrars []RouteRegistrar,
) (*Router, error)

func (*Router) Group added in v0.3.1

func (r *Router) Group(prefix ...string) *Router

Group returns a child Router sharing the same underlying ServeMux but with an independent copy of the current middleware chain, so further Use() calls on the child don't affect the parent or any sibling groups.

An optional path prefix can be passed to scope routes registered on the child. The prefix is cumulative: if a parent already carries "/api/v1" and the child adds "/clusters", routes on the child are prefixed with "/api/v1/clusters". Omitting the prefix inherits the parent's prefix as-is.

func (*Router) Handle added in v0.3.1

func (r *Router) Handle(pattern string, handler http.Handler)

Handle registers handler for pattern, wrapped with this router's current middleware chain. If the router carries a prefix, it is prepended to the path component of the pattern automatically.

func (*Router) HandleFunc added in v0.3.1

func (r *Router) HandleFunc(pattern string, handler http.HandlerFunc)

HandleFunc registers handler for pattern, wrapped with this router's current middleware chain.

func (*Router) Handler added in v0.3.1

func (r *Router) Handler(req *http.Request) (http.Handler, string)

Handler returns the handler and matched pattern for req without invoking it, delegating to the underlying http.ServeMux. Mainly useful in tests that want to assert a route was registered without executing its side effects.

func (*Router) ServeHTTP added in v0.3.1

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP satisfies http.Handler, allowing a Router to be used directly as an http.Server's Handler or wrapped by further http.Handler middleware.

func (*Router) Use added in v0.3.1

func (r *Router) Use(mw ...Middleware)

Use appends middlewares to this router's chain. Only routes registered after this call (on this router or a Group() derived from it afterwards) will be wrapped by them.

type Server

type Server interface {
	Start()
	Stop() error
	Listen() (net.Listener, error)
	Serve(net.Listener)
}

func NewHealthServer

func NewHealthServer() Server

func NewMetricsServer

func NewMetricsServer() Server

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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