Documentation
¶
Index ¶
- Constants
- Variables
- type Config
- type HTTPServer
- type Middleware
- type Option
- type Router
- func (r *Router) Group(configure func(r *Router))
- func (r *Router) Handle(pattern string, handler http.Handler)
- func (r *Router) HandleFunc(pattern string, handler http.HandlerFunc)
- func (r *Router) ServeHTTP(resp http.ResponseWriter, req *http.Request)
- func (r *Router) Use(middlewares ...Middleware)
Constants ¶
View Source
const ( DefaultHost = "127.0.0.1" DefaultReadTimeout = time.Second * 30 DefaultReadHeaderTimeout = time.Second * 10 DefaultWriteTimeout = time.Second * 30 DefaultIdleTimeout = time.Second * 120 DefaultPort = 8080 )
View Source
const StartupCheckTimeout = 100 * time.Millisecond
Variables ¶
View Source
var ( ErrInvalidHost = errors.New("httpserver: host must be a valid network address") ErrInvalidBasePath = errors.New( "httpserver: base path must be an absolute path without trailing slash", ) ErrMissingCertFile = errors.New( "httpserver: cert file must be specified if key file is specified", ) ErrMissingKeyFile = errors.New( "httpserver: key file must be specified if cert file is specified", ) ErrUnreadableCertFile = errors.New("httpserver: cert file must be readable") ErrUnreadableKeyFile = errors.New("httpserver: key file must be readable") ErrInvalidReadTimeout = errors.New("httpserver: read timeout must be positive") ErrInvalidReadHeaderTimeout = errors.New("httpserver: read header timeout must be positive") ErrInvalidPort = errors.New("httpserver: port must be between 1 and 65535") )
View Source
var (
ErrInvalidContext = errors.New("httpserver: context must not be nil or cancelled")
)
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Host represents network host address.
Host string `json:"host" yaml:"host"`
// BasePath represents the prefixed path in the URL.
BasePath string `json:"basePath" yaml:"basePath"`
// CertFile represents the path to the certificate file.
CertFile string `json:"certFile" yaml:"certFile"`
// KeyFile represents the path to the key file.
KeyFile string `json:"keyFile" yaml:"keyFile"`
// ReadTimeout represents the maximum duration before timing out read of the request.
ReadTimeout time.Duration `json:"readTimeout" yaml:"readTimeout"`
// ReadHeaderTimeout represents the amount of time allowed to read request headers.
ReadHeaderTimeout time.Duration `json:"readHeaderTimeout" yaml:"readHeaderTimeout"`
// WriteTimeout represents the maximum duration before timing out writes of the response.
WriteTimeout time.Duration `json:"writeTimeout" yaml:"writeTimeout"`
// IdleTimeout represents the maximum amount of time to wait for the next request when keep-alive is enabled.
IdleTimeout time.Duration `json:"idleTimeout" yaml:"idleTimeout"`
// Port specifies the port to be used for connections.
Port int `json:"port" yaml:"port"`
// EnableH2C indicates whether HTTP/2 Cleartext (H2C) protocol support is enabled for the Server.
// Use this only if you have configured a reverse proxy that terminates TLS.
EnableH2C bool `json:"enableH2C" yaml:"enableH2C"`
}
Config defines the essential parameters for serving an http Server.
func (*Config) SetDefaults ¶
func (r *Config) SetDefaults()
SetDefaults initializes the default values for the relevant fields in the struct.
type HTTPServer ¶
type HTTPServer struct {
Log log.Logger
Server *http.Server
// contains filtered or unexported fields
}
func New ¶
func New(cfg *Config, opts ...Option) *HTTPServer
type Option ¶
type Option func(*HTTPServer)
Option is a functional option for configuring HTTPServer.
func WithHandler ¶
func WithLogger ¶
type Router ¶
func (*Router) HandleFunc ¶
func (r *Router) HandleFunc(pattern string, handler http.HandlerFunc)
func (*Router) Use ¶
func (r *Router) Use(middlewares ...Middleware)
Click to show internal directories.
Click to hide internal directories.