httpserverfx

package
v0.0.0-...-1ed423c Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package httpserverfx provides an fx module for HTTP server with Chi router.

Index

Constants

This section is empty.

Variables

View Source
var Module = fx.Module(
	"httpserverfx",
	fx.Provide(provideConfiguration, NewHTTPServer),

	fx.Invoke(func(_ *http.Server) {}),
)

Functions

This section is empty.

Types

type Configuration

type Configuration struct {
	Port              uint16            `yaml:"port" env:"PORT,overwrite" validate:"required,gte=1,lte=65535"`
	RequestTimeout    uint8             `yaml:"request_timeout" env:"REQUEST_TIMEOUT,overwrite" validate:"required,gte=1,lte=120"`
	ReadHeaderTimeout uint8             `yaml:"read_header_timeout" env:"READ_HEADER_TIMEOUT,overwrite" validate:"lte=120"`
	ReadTimeout       uint8             `yaml:"read_timeout" env:"READ_TIMEOUT,overwrite" validate:"lte=120"`
	IdleTimeout       uint16            `yaml:"idle_timeout" env:"IDLE_TIMEOUT,overwrite" validate:"lte=600"`
	Cors              CorsConfiguration `yaml:"cors" env:"CORS,overwrite"`
}

func (*Configuration) Validate

func (c *Configuration) Validate() error

type CorsConfiguration

type CorsConfiguration struct {
	AllowedOrigins   []string `yaml:"allowed_origins" env:"ALLOWED_ORIGINS,overwrite"`
	AllowedMethods   []string `yaml:"allowed_methods" env:"ALLOWED_METHODS,overwrite"`
	AllowedHeaders   []string `yaml:"allowed_headers" env:"ALLOWED_HEADERS,overwrite"`
	AllowCredentials bool     `yaml:"allow_credentials" env:"ALLOW_CREDENTIALS,overwrite"`
	MaxAge           int      `yaml:"max_age" env:"MAX_AGE,overwrite" validate:"gte=0,lte=86400"`
}

type Params

type Params struct {
	fx.In
	Lifecycle fx.Lifecycle
	Config    *Configuration
	Logger    *slog.Logger
}

type Result

type Result struct {
	fx.Out
	Server *http.Server
	Mux    *chi.Mux
}

func NewHTTPServer

func NewHTTPServer(p Params) (Result, error)

type WithHTTPServer

type WithHTTPServer interface {
	HTTPServerConfiguration() *Configuration
}

Jump to

Keyboard shortcuts

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