api

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2025 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteError

func WriteError(w http.ResponseWriter, r *http.Request, status int, code, message string, details any)

WriteError writes a standardized error response with request tracking.

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, data any)

WriteJSON writes a JSON response.

Types

type Config

type Config struct {
	ListenAddr        string        `mapstructure:"listen_addr" yaml:"listen_addr"`
	ReadHeaderTimeout time.Duration `mapstructure:"read_header_timeout" yaml:"read_header_timeout"`
	ReadTimeout       time.Duration `mapstructure:"read_timeout" yaml:"read_timeout"`
	WriteTimeout      time.Duration `mapstructure:"write_timeout" yaml:"write_timeout"`
	IdleTimeout       time.Duration `mapstructure:"idle_timeout" yaml:"idle_timeout"`
	MaxHeaderBytes    int           `mapstructure:"max_header_bytes" yaml:"max_header_bytes"`
}

Config defines runtime parameters for the HTTP API server.

func DefaultConfig

func DefaultConfig() Config

type Server

type Server struct {
	Router *mux.Router
	// contains filtered or unexported fields
}

func NewServer

func NewServer(cfg Config, log zerolog.Logger) *Server

func (*Server) EnableCORS

func (s *Server) EnableCORS()

EnableCORS enables permissive CORS. Use sparingly in prod.

func (*Server) Start

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

Start runs the HTTP server with a dedicated listener and graceful shutdown

func (*Server) Use

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

Use appends middleware to the chain and rebuilds the handler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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