server

package
v1.9.0 Latest Latest
Warning

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

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

Documentation

Overview

Package server owns Herald's HTTP lifecycle: it builds a TLS or plaintext listener from config, starts serving, and performs an ordered graceful shutdown (stop accepting -> drain in-flight -> flush audit writer -> shutdown tracer). Startup errors are returned to the caller instead of calling log.Fatal deep in the stack, so main can decide how to exit and tests can assert on failures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunAll added in v1.0.0

func RunAll(ctx context.Context, servers ...*Server) error

RunAll starts each server with a shared cancellation scope. If any listener exits, the others are shut down and drained before RunAll returns.

Types

type Config

type Config struct {
	// Addr is the listen address (e.g. ":8080").
	Addr string
	// LoopbackOnly rejects wildcard and non-loopback addresses. It is intended
	// for administrative listeners that must never be publicly reachable.
	LoopbackOnly bool

	// TLSCertFile / TLSKeyFile enable TLS when both are set.
	TLSCertFile string
	TLSKeyFile  string
	// TLSClientCAFile enables mTLS (client certificate verification) when set.
	// It requires TLSCertFile/TLSKeyFile.
	TLSClientCAFile string
	// ClientCertMode controls client certificate negotiation independently from
	// request authentication: off, optional, or require.
	ClientCertMode string

	// ShutdownTimeout bounds the graceful drain window.
	ShutdownTimeout time.Duration

	Logger *logger.Logger
}

Config describes how to start the server.

type Server

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

Server wraps a Fiber app plus its lifecycle configuration.

func New

func New(app *fiber.App, cfg Config) (*Server, error)

New validates the configuration and returns a Server. It returns an error (rather than aborting) for any misconfiguration so the caller controls exit.

func (*Server) OnShutdown

func (s *Server) OnShutdown(h ShutdownHook)

OnShutdown registers a hook to run during graceful shutdown, after the HTTP server stops accepting connections.

func (*Server) Run

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

Run starts the server and blocks until ctx is cancelled or the server exits with an error. On ctx cancellation it performs an ordered graceful shutdown. It returns nil on a clean shutdown.

func (*Server) TLSEnabled

func (s *Server) TLSEnabled() bool

TLSEnabled reports whether the server will terminate TLS.

type ShutdownHook

type ShutdownHook func(ctx context.Context) error

ShutdownHook runs during graceful shutdown. Hooks run in registration order after the HTTP server has stopped accepting new connections.

Jump to

Keyboard shortcuts

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