svcboot

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package svcboot starts every service the same way: server, request IDs, metrics and tracing.

Run(Config) builds the http.Server with safe timeouts, wraps the handler with request IDs, request metrics and tracing, and serves until shutdown. APIKeySet and APIKeysFromEnv parse comma-separated API key lists. Services call it from main so they all start, log and shut down the same way.

Index

Constants

View Source
const (
	DefaultReadHeaderTimeout = 5 * time.Second
	DefaultReadTimeout       = 15 * time.Second
	DefaultWriteTimeout      = 15 * time.Second
	DefaultIdleTimeout       = 60 * time.Second
)

Default per-connection timeouts for split API services. Routes that accept large uploads or run long operations (for example the runtime-api registry push) extend their own deadlines with http.ResponseController instead of raising these for every route.

Variables

This section is empty.

Functions

func APIKeySet

func APIKeySet(envValue string) map[string]struct{}

APIKeySet parses comma-separated API keys into a lookup set.

func APIKeysFromEnv

func APIKeysFromEnv(name string) map[string]struct{}

APIKeysFromEnv reads a comma-separated API key list from the named variable.

func NewHTTPServer

func NewHTTPServer(addr string, handler http.Handler) *http.Server

NewHTTPServer returns the service HTTP server with the shared default timeouts.

func Run

func Run(cfg Config) error

Run starts metrics, OTEL-instrumented HTTP, and blocks until shutdown.

func WithRequestID

func WithRequestID(next http.Handler) http.Handler

WithRequestID gives every request an identifier and returns it in the X-Request-Id response header. A well-formed identifier from the caller is kept so a trace can span services; anything else is replaced, never echoed, so the header cannot carry injected data. The same identifier is stored on the request context, which is where audit writes and access logs read it.

func WrapHandler

func WrapHandler(serviceName string, requestMetrics *telemetry.RequestMetrics, next http.Handler) http.Handler

WrapHandler applies the shared OTEL, request logging, and request metrics middleware. The wrapped writers unwrap to the connection's writer, so handlers can still use http.ResponseController to extend deadlines.

Types

type Config

type Config struct {
	ServiceName string
	Port        string
	MetricsPort string
	Handler     http.Handler
	OnShutdown  func(context.Context) error
}

Config drives the shared HTTP + metrics + OTEL bootstrap for split API services.

Jump to

Keyboard shortcuts

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