Documentation ¶
Overview ¶
Package lui is a convenience wrapper around net/http. It contains functionality to quickly setup and run common http/https configurations.
Index ¶
- Constants
- type OptionFunc
- func HTTPAddr(addr string) OptionFunc
- func HTTPSAddr(addr string) OptionFunc
- func IdleTimeout(t time.Duration) OptionFunc
- func ReadHeaderTimeout(t time.Duration) OptionFunc
- func ReadTimeout(t time.Duration) OptionFunc
- func ShutdownTimeout(t time.Duration) OptionFunc
- func TLSAuto(email, dirCache string, hostnames ...string) OptionFunc
- func TLSAutoManager(m *autocert.Manager) OptionFunc
- func TLSFiles(certFile, keyFile string) OptionFunc
- func WriteTimeout(t time.Duration) OptionFunc
- type Server
Constants ¶
const ( // DefaultReadTimeout is the read timeout used by https/https servers when no specific read timeout is provided DefaultReadTimeout = time.Second * 10 // DefaultHeaderReadTimeout is the read timeout used by https/https servers when no specific read header timeout is provided DefaultHeaderReadTimeout = time.Second * 5 // DefaultWriteTimeout is the read timeout used by https/https servers when no specific timeout is provided DefaultWriteTimeout = time.Second * 30 // DefaultIdleTimeout is the idle timeout used by https/https servers when no specific timeout is provided DefaultIdleTimeout = time.Second * 60 // DefaultShutdownTimeout is the shutdown timeout used by https/https servers when no specific timeout is provided DefaultShutdownTimeout = time.Second * 30 // DefaultHTTPAddr is the default http address DefaultHTTPAddr = ":80" // DefaultHTTPSAddr is the default https address DefaultHTTPSAddr = ":443" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type OptionFunc ¶
OptionFunc configures an option on the server
func HTTPAddr ¶
func HTTPAddr(addr string) OptionFunc
HTTPAddr option sets the address on which the http server listens
func HTTPSAddr ¶
func HTTPSAddr(addr string) OptionFunc
HTTPSAddr option sets the address on which the https server listens
func IdleTimeout ¶
func IdleTimeout(t time.Duration) OptionFunc
IdleTimeout option sets a specific idle timeout. Set to 0 for no timeout (not recommended)
func ReadHeaderTimeout ¶
func ReadHeaderTimeout(t time.Duration) OptionFunc
ReadHeaderTimeout option sets a specific read timeout. Set to 0 for no timeout (not recommended)
func ReadTimeout ¶
func ReadTimeout(t time.Duration) OptionFunc
ReadTimeout option sets a specific read timeout. Set to 0 for no timeout (not recommended)
func ShutdownTimeout ¶
func ShutdownTimeout(t time.Duration) OptionFunc
ShutdownTimeout option sets a specific shutdown timeout. Set to 0 for direct shutdown
func TLSAuto ¶
func TLSAuto(email, dirCache string, hostnames ...string) OptionFunc
TLSAuto option configures TLS via a basic autocert manager
func TLSAutoManager ¶
func TLSAutoManager(m *autocert.Manager) OptionFunc
TLSAutoManager option configures TLS via the provided autocert manager
func TLSFiles ¶
func TLSFiles(certFile, keyFile string) OptionFunc
TLSFiles option configures TLS via the provided certificate and key files. When this option is provided the main handler will be served over https
func WriteTimeout ¶
func WriteTimeout(t time.Duration) OptionFunc
WriteTimeout option sets a specific write timeout. Set to 0 for no timeout (not recommended)
type Server ¶
type Server struct { // ShutdownTimeout specifies how long to wait until we cancel a graceful shutdown ShutdownTimeout time.Duration // HTTP serves a handler over http. If a TLS option is provided, this // handler will be a redirect handler that redirects to https. HTTP *http.Server // HTTPS serves the main handler over https. Can be nil when only serving over http HTTPS *http.Server // contains filtered or unexported fields }
Server uses net/http servers to serve a handler
func New ¶
func New(handler http.Handler, options ...OptionFunc) (*Server, error)
New creates a new server configured with the provided options.
func (*Server) ListenAndServe ¶
ListenAndServe runs the server until it receives a kill signal or one of the http servers fails