server

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: AGPL-3.0 Imports: 20 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildHandler

func BuildHandler(ctx context.Context, cfg Config, handler http.Handler) http.Handler

BuildHandler composes the middleware chain around the given handler. Zero-value rate limit fields default to 120/120 read and 60/60 write.

func CORSMiddleware

func CORSMiddleware(origins []string) func(http.Handler) http.Handler

CORSMiddleware returns middleware that sets CORS headers for the given origins. If origins is empty, no CORS headers are set (same-origin only).

func RateLimiter

func RateLimiter(ctx context.Context, readRPS float64, readBurst int, writeRPS float64, writeBurst int, trustProxy bool, proxyDepth int) func(http.Handler) http.Handler

RateLimiter returns middleware that limits requests per IP address. rps is requests per second, burst is the maximum burst size. When trustProxy is true, X-Forwarded-For / X-Real-Ip headers are used for client IP. The cleanup goroutine exits when ctx is cancelled.

func RequestLogger

func RequestLogger(trustProxy bool, proxyDepth int) func(http.Handler) http.Handler

RequestLogger returns middleware that logs each request. Logs: timestamp, method, path, status code, duration, client IP. Sensitive data (bodies, auth headers) is never logged.

Types

type Config

type Config struct {
	BaseURL        *baseurl.BaseURL
	TrustProxy     bool
	ProxyDepth     int
	CORSOrigins    []string
	ReadRPS        float64
	ReadBurst      int
	WriteRPS       float64
	WriteBurst     int
	Version        string
	AdminToken     string
	MaxSecretSize  int // bytes; 0 = default (512000)
	MetricsEnabled bool

	// ExtraRoutes registers additional routes on the server mux. nil = no extra routes.
	ExtraRoutes func(mux *http.ServeMux)

	// Middleware is a chain of additional middleware applied after security headers.
	// Each function wraps the handler; they are applied in slice order (last = outermost).
	Middleware []func(http.Handler) http.Handler
}

type Server

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

func New

func New(ctx context.Context, cfg Config, st *store.Store, webFS fs.FS) *Server

func (*Server) Handler

func (s *Server) Handler() http.Handler

Jump to

Keyboard shortcuts

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