Documentation
¶
Overview ¶
Package stdlib provides a routing.Backend built on the standard library's net/http.ServeMux. It adds no third-party router dependency: Go's mux already supports method-scoped patterns ("GET /users/{id}") and per-request path values, which is exactly the shape routing.Backend needs. The shared observability, recovery, CORS, and OpenTelemetry middleware stack is applied around the mux, matching the chi backend's behavior.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewBackend ¶
func NewBackend(logger logging.Logger, tracerProvider tracing.TracerProvider, metricProvider metrics.Provider, cfg *Config) routing.Backend
NewBackend constructs a net/http-backed routing.Backend with the standard middleware and OpenTelemetry stack installed. Pass it to routing.New.
func RequestIDFunc ¶
RequestIDFunc returns the request ID assigned to a request by the backend's request-ID middleware, or "" if none is present. It can be handed to logging.Logger.SetRequestIDFunc so log lines carry the request ID.
Types ¶
type Config ¶
type Config struct {
ServiceName string `env:"SERVICE_NAME" json:"serviceName,omitempty" yaml:"serviceName,omitempty"`
ValidDomains []string `env:"VALID_DOMAINS" json:"validDomains,omitempty" yaml:"validDomains,omitempty"`
EnableCORSForLocalhost bool `env:"ENABLE_CORS_FOR_LOCALHOST" json:"enableCORSForLocalhost" yaml:"enableCORSForLocalhost"`
SilenceRouteLogging bool `env:"SILENCE_ROUTE_LOGGING" json:"silenceRouteLogging,omitempty" yaml:"silenceRouteLogging,omitempty"`
// contains filtered or unexported fields
}
Config configures the stdlib (net/http.ServeMux) router backend. Its fields mirror the other backends so a service can switch backends without changing its configuration shape.