server

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package server provides an HTTP/HTTPS server with graceful shutdown support, built on top of fasthttp.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunSignalHandler

func RunSignalHandler(ctx context.Context, srv *Server, c *cache.Cache, cfgPath string, cfgPtr **config.Config, pc ...*security.PathCache)

RunSignalHandler blocks until SIGTERM or SIGINT is received, then gracefully shuts down srv. It also handles SIGHUP to reload configuration and flush cache.

Parameters:

  • ctx: parent context (used to derive a shutdown context)
  • srv: the running Server
  • c: the cache to flush on SIGHUP
  • cfgPath: path to the TOML config file (used for SIGHUP reload)
  • cfgPtr: pointer to the current config pointer, updated on reload
  • pc: optional path cache to flush on SIGHUP (may be nil)

Types

type Server

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

Server wraps one HTTP and one optional HTTPS fasthttp.Server.

func New

New creates a Server from the provided configuration and handler. HTTPS is only configured when both TLSCert and TLSKey are non-empty. When TLS is configured, the HTTP server is replaced with a redirect handler that sends all requests to the HTTPS address (SEC-004).

func (*Server) Shutdown

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

Shutdown gracefully drains all active connections. It calls Shutdown on both HTTP and HTTPS servers concurrently. Returns the first error encountered, or nil if both complete cleanly.

func (*Server) Start

func (s *Server) Start(cfg *config.ServerConfig) error

Start begins listening on HTTP (and HTTPS if configured) concurrently. It blocks until both listeners have started or one returns an error. Returns the first error encountered.

Jump to

Keyboard shortcuts

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