Documentation ¶
Overview ¶
Package tinyhttp provides HTTP server implementation.
Index ¶
- type Server
- type ServerConfig
- type ServerOpt
- func GinMode(mode string) ServerOpt
- func IdleTimeout(timeout time.Duration) ServerOpt
- func MaxHeaderBytes(maxHeaderBytes int) ServerOpt
- func MethodNotAllowed(methodNotAllowed bool) ServerOpt
- func Network(network string) ServerOpt
- func ReadHeaderTimeout(timeout time.Duration) ServerOpt
- func ReadTimeout(timeout time.Duration) ServerOpt
- func RemoteIPHeaders(headers []string) ServerOpt
- func SecurityHeaders(securityHeaders bool) ServerOpt
- func ShutdownTimeout(timeout time.Duration) ServerOpt
- func TLS(cert, key string, tlsConfig ...*tls.Config) ServerOpt
- func TrustedProxies(trustedProxies []string) ServerOpt
- func WriteTimeout(timeout time.Duration) ServerOpt
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶
Server is an object representing gin.Engine and implementing the tiny.Service interface.
func (*Server) OnNoRoute ¶
OnNoRoute sets a handler for requests that cannot be routed and would end up as 404s.
func (*Server) OnPanic ¶
OnPanic sets a handler for requests that resulted in panic and would end up as 500s.
type ServerConfig ¶
type ServerConfig struct { // Network is a network type for the listener (default: "tcp"). Network string // GinMode defines working mode of the Gin library (default: Release). GinMode string // SecurityHeaders defines whether to include HTTP security headers to all responses or not (default: true). SecurityHeaders bool // MethodNotAllowed defines whether the library handles method not allowed errors (default: false). MethodNotAllowed 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 // TLSConfig is an optional TLS configuration to pass when using TLS mode. TLSConfig *tls.Config // ReadTimeout is a timeout used when creating underlying http server (see http.Server) (default: 5s). ReadTimeout time.Duration // ReadHeaderTimeout is a timeout used when creating underlying http server (see http.Server). ReadHeaderTimeout time.Duration // WriteTimeout is a timeout used when creating underlying http server (see http.Server) (default: 10s). WriteTimeout time.Duration // IdleTimeout is a timeout used when creating underlying http server (see http.Server) (default 2m). IdleTimeout time.Duration // MaxHeaderBytes is a value used when creating underlying http server (see http.Server). MaxHeaderBytes int // 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") RemoteIPHeaders []string // 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 IdleTimeout ¶
IdleTimeout is a timeout used when creating underlying http server (see http.Server).
func MaxHeaderBytes ¶
MaxHeaderBytes is a value used when creating underlying http server (see http.Server).
func MethodNotAllowed ¶ added in v1.0.24
MethodNotAllowed defines whether the library handles method not allowed errors.
func ReadHeaderTimeout ¶
ReadHeaderTimeout is a timeout used when creating underlying http server (see http.Server).
func ReadTimeout ¶
ReadTimeout is a timeout used when creating underlying http server (see http.Server).
func RemoteIPHeaders ¶
RemoteIPHeaders is a list of headers that overwrite 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 TLS ¶
TLS enables TLS mode if both cert and key point to valid TLS credentials. tlsConfig is optional.
func TrustedProxies ¶
TrustedProxies is a list of CIDR address ranges that can be trusted when handling RemoteIP header.
func WriteTimeout ¶
WriteTimeout is a timeout used when creating underlying http server (see 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 ExtractValidatorErrors ¶ added in v1.0.21
func ExtractValidatorErrors(err error) []ValidationError
ExtractValidatorErrors tries to extract an array of ValidationError from given error.