server

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterRuntimeExtension

func RegisterRuntimeExtension(ext RuntimeExtension)

RegisterRuntimeExtension registers a server runtime extension.

Duplicate names are ignored to keep registration idempotent.

Types

type GRPCServer

type GRPCServer interface {
	Start() error
	Stop()
}

GRPCServer abstracts product-specific gRPC implementation.

type GracefulGRPCServer

type GracefulGRPCServer interface {
	GRPCServer
	GracefulStop(context.Context) error
}

GracefulGRPCServer optionally supports context-aware graceful shutdown.

type HTTPRuntime

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

HTTPRuntime wires shared health, metrics, routes, and extension lifecycle.

func MustNewHTTPRuntime

func MustNewHTTPRuntime(cfg HTTPRuntimeConfig) *HTTPRuntime

MustNewHTTPRuntime is a convenience helper for bootstrapping examples/tests.

func NewHTTPRuntime

func NewHTTPRuntime(cfg HTTPRuntimeConfig) (*HTTPRuntime, error)

NewHTTPRuntime creates a DenseCloud-owned shared HTTP runtime assembly.

func (*HTTPRuntime) APIMux

func (r *HTTPRuntime) APIMux() *http.ServeMux

APIMux returns the /v1 API sub-mux owned by the runtime.

func (*HTTPRuntime) Handler

func (r *HTTPRuntime) Handler() http.Handler

Handler returns the fully assembled root handler.

func (*HTTPRuntime) Health

func (r *HTTPRuntime) Health() *HealthRegistry

Health returns the runtime's shared health registry.

func (*HTTPRuntime) Metrics

func (r *HTTPRuntime) Metrics() *telemetry.HTTPMetrics

Metrics returns the runtime's shared HTTP metrics collector.

func (*HTTPRuntime) RootMux

func (r *HTTPRuntime) RootMux() *http.ServeMux

RootMux returns the root mux owned by the runtime.

func (*HTTPRuntime) Shutdown

func (r *HTTPRuntime) Shutdown(ctx context.Context) error

Shutdown fail-closes readiness and runs runtime shutdown hooks.

func (*HTTPRuntime) Startup

func (r *HTTPRuntime) Startup(ctx context.Context) error

Startup initializes registered extensions and marks startup complete.

type HTTPRuntimeConfig

type HTTPRuntimeConfig struct {
	ServiceName                 string
	RootMux                     *http.ServeMux
	APIMux                      *http.ServeMux
	APIBasePath                 string
	RootMiddleware              []func(http.Handler) http.Handler
	APIMiddleware               []func(http.Handler) http.Handler
	Health                      *HealthRegistry
	Metrics                     *telemetry.HTTPMetrics
	MetricsPath                 string
	DisableHealthRoutes         bool
	DisableMetricsRoute         bool
	DisableRegisteredExtensions bool
	StartupHooks                []StartupHook
	ShutdownHooks               []ShutdownHook
}

HTTPRuntimeConfig defines DenseCloud's shared HTTP chassis assembly.

type HealthCheck

type HealthCheck func(context.Context) error

HealthCheck verifies runtime liveness/readiness/startup conditions.

type HealthCheckResult

type HealthCheckResult struct {
	Name   string `json:"name"`
	Status string `json:"status"`
	Error  string `json:"error,omitempty"`
}

HealthCheckResult captures the state of a named health check.

type HealthDependency

type HealthDependency interface {
	HealthCheck(context.Context) error
}

HealthDependency is implemented by dependencies that can self-check.

type HealthPhase

type HealthPhase string

HealthPhase describes a shared DenseCloud health lifecycle phase.

const (
	HealthPhaseLive    HealthPhase = "live"
	HealthPhaseReady   HealthPhase = "ready"
	HealthPhaseStartup HealthPhase = "startup"
)

type HealthRegistry

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

HealthRegistry owns DenseCloud's shared health lifecycle contract.

func NewHealthRegistry

func NewHealthRegistry() *HealthRegistry

NewHealthRegistry creates a registry with conservative startup defaults.

func (*HealthRegistry) MarkShuttingDown

func (r *HealthRegistry) MarkShuttingDown()

MarkShuttingDown flips readiness to fail-close mode.

func (*HealthRegistry) MarkStarted

func (r *HealthRegistry) MarkStarted()

MarkStarted flips startup/readiness into serviceable mode.

func (*HealthRegistry) RegisterCheck

func (r *HealthRegistry) RegisterCheck(name string, fn HealthCheck, phases ...HealthPhase)

RegisterCheck registers the same check across one or more phases.

func (*HealthRegistry) RegisterDependency

func (r *HealthRegistry) RegisterDependency(name string, dependency HealthDependency, phases ...HealthPhase)

RegisterDependency registers a dependency health check across one or more phases.

func (*HealthRegistry) RegisterHandlers

func (r *HealthRegistry) RegisterHandlers(mux *http.ServeMux)

RegisterHandlers mounts the standard DenseCloud health endpoints.

func (*HealthRegistry) RegisterLiveness

func (r *HealthRegistry) RegisterLiveness(name string, fn HealthCheck)

RegisterLiveness adds a liveness check.

func (*HealthRegistry) RegisterReadiness

func (r *HealthRegistry) RegisterReadiness(name string, fn HealthCheck)

RegisterReadiness adds a readiness check.

func (*HealthRegistry) RegisterStartup

func (r *HealthRegistry) RegisterStartup(name string, fn HealthCheck)

RegisterStartup adds a startup check.

type HealthReport

type HealthReport struct {
	Status string              `json:"status"`
	Phase  string              `json:"phase"`
	Checks []HealthCheckResult `json:"checks,omitempty"`
}

HealthReport is the JSON payload returned by health endpoints.

type Options

type Options struct {
	HTTPServer      *http.Server
	GRPCServer      GRPCServer
	EnableGRPC      bool
	ShutdownTimeout time.Duration
	StartupHooks    []StartupHook
	ShutdownHooks   []ShutdownHook
}

Options define shared server runtime behavior.

type Runner

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

Runner starts/stops HTTP and optional gRPC with signal-aware graceful shutdown.

func NewRunner

func NewRunner(opts Options) (*Runner, error)

NewRunner creates a new shared runtime runner.

func (*Runner) RunBlocking

func (r *Runner) RunBlocking(ctx context.Context) error

RunBlocking runs until signal, context cancellation, or server error.

func (*Runner) Shutdown

func (r *Runner) Shutdown(ctx context.Context) error

Shutdown gracefully stops HTTP, gRPC and product-defined hooks.

type RuntimeExtension

type RuntimeExtension interface {
	// Name returns a stable extension identifier.
	Name() string

	// APIMiddleware returns middleware to apply to /v1 API routes.
	APIMiddleware() []func(http.Handler) http.Handler

	// RegisterRoutes lets the extension mount HTTP handlers.
	//
	// rootMux is the top-level server mux, apiMux is the /v1 sub-mux.
	RegisterRoutes(rootMux, apiMux *http.ServeMux)

	// Startup runs before serving traffic.
	Startup(ctx context.Context) error

	// Shutdown runs during graceful termination.
	Shutdown(ctx context.Context) error
}

RuntimeExtension is an optional server extension that can inject middleware, routes, and startup/shutdown hooks at runtime.

Implementations are typically registered from separate modules via init().

func RuntimeExtensions

func RuntimeExtensions() []RuntimeExtension

RuntimeExtensions returns a snapshot of all registered extensions.

type ShutdownHook

type ShutdownHook func(context.Context) error

ShutdownHook allows apps to close domain resources during shutdown.

type StartupHook

type StartupHook func(context.Context) error

StartupHook allows apps to initialize shared runtime resources before serving.

Jump to

Keyboard shortcuts

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