server

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package server provides the Fiber HTTP server with built-in middleware, TLS, and security features.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Duration

func Duration(s string, fallback time.Duration) time.Duration

Types

type AutocertTLS added in v0.1.0

type AutocertTLS struct {
	Domains  []string `json:"domains"`
	Email    string   `json:"email"`
	CacheDir string   `json:"cache_dir" config:",optional"`
	Staging  bool     `json:"staging" config:",optional"`
}

type CORSConfig

type CORSConfig struct {
	Origins     []string
	Methods     []string
	Headers     []string
	Credentials bool
	MaxAge      int
}

type Config

type Config struct {
	Port            int
	Host            string
	Prefork         bool
	BodyLimit       int
	Timeout         time.Duration
	ReadTimeout     time.Duration
	WriteTimeout    time.Duration
	IdleTimeout     time.Duration
	MaxConns        int
	MaxBytes        int
	MetricsPath     string
	HealthPath      string
	ShutdownTimeout time.Duration
	RecoverStack    bool
	APIPrefix       string
	Routes          []RouteConfig

	Logger            bool
	LoadShedding      bool
	Breaker           bool
	Compression       bool
	StreamRequestBody bool
	ReduceMemoryUsage bool

	// Security
	SecurityHeaders *middleware.SecurityHeadersConfig
	CSRF            *middleware.CSRFConfig
	RateLimit       *middleware.RateLimitConfig
	TLS             *TLSConfig
	SSRF            *middleware.SSRFConfig
	// Correlation enables the X-Correlation-ID tracking middleware.
	Correlation *CorrelationConfig

	// Logger config
	LogSkipPaths  []string
	LogSampleRate float64
}

func DefaultConfig

func DefaultConfig() Config

type ContentSecurityConf

type ContentSecurityConf struct {
	Enabled   bool
	Strict    bool
	PublicKey string
}

type CorrelationConfig added in v0.11.0

type CorrelationConfig struct {
	Enabled        bool
	RequestHeader  string
	ResponseHeader string
	SkipPaths      []string
}

type CryptionConf

type CryptionConf struct {
	Enabled bool
	Key     string
}

type EncryptCookieConf added in v0.8.0

type EncryptCookieConf struct {
	Enabled bool
	Key     string
	Except  []string
}

type ErrorResponse

type ErrorResponse struct {
	Code    int    `json:"code"`
	Error   string `json:"error,omitempty"`
	Message string `json:"message"`
}

type LocalStorage

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

func NewLocalStorage

func NewLocalStorage(root string) (*LocalStorage, error)

func (*LocalStorage) Delete

func (l *LocalStorage) Delete(_ context.Context, key string) error

func (*LocalStorage) Download

func (l *LocalStorage) Download(_ context.Context, key string) (io.ReadCloser, error)

func (*LocalStorage) Upload

func (l *LocalStorage) Upload(_ context.Context, key string, reader io.Reader, _ int64, _ string) error

type ManualTLS added in v0.1.0

type ManualTLS struct {
	CertFile string `json:"cert_file"`
	KeyFile  string `json:"key_file"`
}

type PoolConfig added in v0.6.0

type PoolConfig struct {
	MaxIdleConns        int
	MaxIdleConnsPerHost int
	MaxConnsPerHost     int
	IdleTimeout         time.Duration
}

type Presigner added in v0.6.0

type Presigner interface {
	PresignURL(ctx context.Context, key string, ttl time.Duration) (string, error)
}

Presigner generates presigned URLs for direct client access. Optional extension of StorageBackend for S3-compatible storage.

type RouteConfig

type RouteConfig struct {
	Path       string
	Middleware []string // middleware names: logger, shedding, breaker, maxconns, maxbytes, gunzip, prometheus, trace, cors, jwt, content_security, cryption
}

type S3Config

type S3Config struct {
	Endpoint        string
	Region          string
	Bucket          string
	AccessKeyID     string
	SecretAccessKey string
	UseSSL          bool
	Pool            *PoolConfig
	PresignTTL      time.Duration
}

type S3Storage

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

func NewS3Storage

func NewS3Storage(cfg S3Config) (*S3Storage, error)

func (*S3Storage) Delete

func (s *S3Storage) Delete(ctx context.Context, key string) error

func (*S3Storage) Download

func (s *S3Storage) Download(ctx context.Context, key string) (io.ReadCloser, error)

func (*S3Storage) PresignTTL added in v0.9.0

func (s *S3Storage) PresignTTL() time.Duration

func (*S3Storage) PresignURL added in v0.6.0

func (s *S3Storage) PresignURL(ctx context.Context, key string, ttl time.Duration) (string, error)

func (*S3Storage) Upload

func (s *S3Storage) Upload(ctx context.Context, key string, reader io.Reader, size int64, contentType string) error

type SecurityConfig

type SecurityConfig struct {
	ContentSecurity *ContentSecurityConf
	Cryption        *CryptionConf
	EncryptCookie   *EncryptCookieConf
}

type Server

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

func New

func New(cfg Config, telemetry TelemetryConfig, security SecurityConfig, corsCfg *CORSConfig) *Server

func (*Server) App

func (s *Server) App() *fiber.App

func (*Server) Start

func (s *Server) Start() error

func (*Server) Stop

func (s *Server) Stop()

type StorageBackend

type StorageBackend interface {
	Upload(ctx context.Context, key string, reader io.Reader, size int64, contentType string) error
	Download(ctx context.Context, key string) (io.ReadCloser, error)
	Delete(ctx context.Context, key string) error
}

StorageBackend abstracts file storage operations.

type TLSConfig added in v0.1.0

type TLSConfig struct {
	Enabled      bool         `json:"enabled"`
	Manual       *ManualTLS   `json:"manual" config:",optional"`
	Autocert     *AutocertTLS `json:"autocert" config:",optional"`
	MinVersion   string       `json:"min_version" config:",optional"`
	MaxVersion   string       `json:"max_version" config:",optional"`
	CurvePrefs   []string     `json:"curve_preferences" config:",optional"`
	CipherSuites []string     `json:"cipher_suites" config:",optional"`
	RedirectHTTP bool         `json:"redirect_http" config:",optional"`
	RedirectPort int          `json:"redirect_port" config:",optional"`
}

type TelemetryConfig

type TelemetryConfig struct {
	Enabled  bool
	Name     string
	Endpoint string
	Sampler  float64
	Batcher  string

	OtlpHeaders         map[string]string
	OtlpHttpPath        string
	OtlpHttpSecure      bool
	TraceResponseHeader string
	SkipPaths           []string
}

Directories

Path Synopsis
auth
openfga
Package openfga provides the OpenFGA authorization client.
Package openfga provides the OpenFGA authorization client.
ory
Package ory provides Ory Kratos authentication and Keto authorization client.
Package ory provides Ory Kratos authentication and Keto authorization client.
zitadel
Package zitadel provides Zitadel OIDC authentication and JWKS-based JWT validation.
Package zitadel provides Zitadel OIDC authentication and JWKS-based JWT validation.
Package middleware provides Fiber HTTP middlewares for auth, security, validation, rate limiting, and more.
Package middleware provides Fiber HTTP middlewares for auth, security, validation, rate limiting, and more.

Jump to

Keyboard shortcuts

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