Documentation
¶
Overview ¶
Package tinyhttp provides HTTP server implementation.
Index ¶
- Variables
- type Server
- type ServerConfig
- type ServerOpt
- func BodyLimit(bodyLimit int) ServerOpt
- func Concurrency(concurrency int) ServerOpt
- func FiberOption(opt func(*fiber.Config)) ServerOpt
- func IdleTimeout(timeout time.Duration) ServerOpt
- func Network(network string) ServerOpt
- func ReadBufferSize(readBufferSize int) ServerOpt
- func ReadTimeout(timeout time.Duration) ServerOpt
- func RemoteIPHeader(header string) ServerOpt
- func SecurityHeaders(securityHeaders bool) ServerOpt
- func ShutdownTimeout(timeout time.Duration) ServerOpt
- func TLS(cert, key string) ServerOpt
- func TrustedProxies(trustedProxies []string) ServerOpt
- func ViewEngine(engine fiber.Views) ServerOpt
- func ViewLayout(layout string) ServerOpt
- func WriteTimeout(timeout time.Duration) ServerOpt
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
var DefaultValidator = validator.New()
DefaultValidator is the default instance of validator.Validate.
Functions ¶
This section is empty.
Types ¶
type Server ¶
Server is an object representing fiber.App and implementing the tiny.Service interface.
func (*Server) OnError ¶ added in v1.0.42
OnError sets a handler for requests that resulted in error.
type ServerConfig ¶
type ServerConfig struct {
// Network is a network type for the listener (default: "tcp").
Network string
// SecurityHeaders defines whether to include HTTP security headers to all responses or not (default: true).
SecurityHeaders bool
// ShutdownTimeout defines a maximal timeout of HTTP server shutdown (default: 5s).
ShutdownTimeout time.Duration
// TLSCert is a path to TLS certificate to use. When specified with TLSKey - enables TLS mode.
TLSCert string
// TLSKey is a path to TLS key to use. When specified with TLSCert - enables TLS mode.
TLSKey string
// ReadTimeout is a timeout used when creating underlying http server (default: 5s).
ReadTimeout time.Duration
// WriteTimeout is a timeout used when creating underlying http server (default: 10s).
WriteTimeout time.Duration
// IdleTimeout is a timeout used when creating underlying http server (default 2m).
IdleTimeout time.Duration
// TrustedProxies is a list of CIDR address ranges that can be trusted when handling RemoteIP header.
// (default: "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "127.0.0.0/8", "fc00::/7", "::1/128")
TrustedProxies []string
// RemoteIPHeaders is a list of headers that overwrite the value of client's remote address.
// (default: "X-Forwarded-For")
RemoteIPHeader string
// ViewEngine is a template rendering engine for fiber (default: nil).
ViewEngine fiber.Views
// ViewLayout is a global layout for ViewEngine (default: "").
ViewLayout string
// Concurrency specifies a maximum number of concurrent connections (default: 256 * 1024).
Concurrency int
// BodyLimit specifies a maximum allowed size for a request body (default: 4 * 1024 * 1024).
BodyLimit int
// ReadBufferSize specifies a per-connection buffer size (default: 4096).
ReadBufferSize int
// contains filtered or unexported fields
}
ServerConfig holds a configuration for NewServer.
type ServerOpt ¶
type ServerOpt = func(*ServerConfig)
ServerOpt is an option to be specified to NewServer.
func Concurrency ¶ added in v1.0.46
Concurrency specifies a maximum number of concurrent connections.
func FiberOption ¶ added in v1.0.46
FiberOption specifies user-defined function that directly modifies fiber config.
func IdleTimeout ¶
IdleTimeout is a timeout used when creating underlying http server.
func ReadBufferSize ¶ added in v1.0.46
ReadBufferSize specifies a per-connection buffer size.
func ReadTimeout ¶
ReadTimeout is a timeout used when creating underlying http server.
func RemoteIPHeader ¶ added in v1.0.38
RemoteIPHeader is a name of the header that overwrites the value of client's remote address.
func SecurityHeaders ¶
SecurityHeaders defines whether to include HTTP security headers to all responses or not.
func ShutdownTimeout ¶
ShutdownTimeout defines a maximal timeout of HTTP server shutdown.
func TrustedProxies ¶
TrustedProxies is a list of CIDR address ranges that can be trusted when handling RemoteIP header.
func ViewEngine ¶ added in v1.0.46
ViewEngine is a template rendering engine for fiber.
func ViewLayout ¶ added in v1.0.46
ViewLayout is a global layout for ViewEngine.
func WriteTimeout ¶
WriteTimeout is a timeout used when creating underlying http server.
type ValidationError ¶ added in v1.0.21
type ValidationError struct {
// Field is a name of the field that contains an error.
Field string `json:"field"`
// Tag is a name of the tag that trigger an error.
Tag string `json:"tag"`
}
ValidationError denotes an error in payload validation.
func BindBody ¶ added in v1.0.40
func BindBody(c *fiber.Ctx, out any) []ValidationError
BindBody tries to parse provided request body and validate resulting object using the DefaultValidator.
func ExtractValidatorErrors ¶ added in v1.0.21
func ExtractValidatorErrors(err error) []ValidationError
ExtractValidatorErrors tries to extract an array of ValidationError from given error.