s3-orchestrator

httpserver

import "github.com/afreidah/s3-orchestrator/internal/transport/httpserver"

Package httpserver constructs the HTTP listener the daemon serves S3, admin, UI, health, and metrics traffic on. It owns route registration, middleware composition, TLS config (including the cert reloader for SIGHUP rotation), and the optional separate metrics listener.

Index

Constants

Daemon mode strings. registerS3Handler and registerUIHandler are only mounted in “api” and “all” modes; worker-only mode exposes neither.

const (
    ModeAPI = "api"
    ModeAll = "all"
)

DrainTimeout is the default Shutdown deadline used by the runtime when the caller does not supply one. Exported so tests can match the production value without coupling to a magic number.

const DrainTimeout = 30 * time.Second

type Deps

Deps holds the dependencies New requires.

type Deps struct {
    Cfg       *config.Config
    Mode      string
    Injector  do.Injector
    Ready     *atomic.Bool
    DBBreaker func() *breaker.CircuitBreaker
}

type HealthDeps

HealthDeps holds the signals the health and readiness handlers read.

type HealthDeps struct {
    // Ready reports whether the daemon has finished initialization and is
    // accepting traffic. Routed to /health/ready.
    Ready *atomic.Bool
    // DBBreaker resolves the database circuit breaker lazily so the health
    // handler reflects breaker state without holding a reference past
    // shutdown. nil is treated as healthy.
    DBBreaker func() *breaker.CircuitBreaker
}

type Server

Server bundles the main HTTP listener with its optional separate metrics listener and the TLS cert reloader. Run starts both listeners; Shutdown closes them in the right order. The cert reloader is exposed so the reload coordinator can refresh certificates without reaching into the listener internals.

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

func New

func New(deps Deps) (*Server, error)

New constructs the HTTP server with all routes mounted and TLS configured. It does not start any listener; call Run to do that.

func (*Server) CertReloader

func (s *Server) CertReloader() *httputil.CertReloader

CertReloader returns the TLS cert reloader, or nil when TLS is not configured. The reload coordinator calls Reload on this to refresh certificates on SIGHUP.

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run starts the metrics listener (if separate) and the main listener. It blocks until either listener returns. The error channel returned by the main listener is forwarded so the runtime can distinguish a natural shutdown (http.ErrServerClosed) from a real failure.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context)

Shutdown drains the main listener (with the supplied context’s timeout) and the metrics listener if present. Errors are logged but do not abort the shutdown sequence; the runtime owns final teardown ordering.

Generated by gomarkdoc