Documentation ¶
Overview ¶
Package server provides HTTP server implementation. The server provided in here is opinionated and comes with good defaults.
Index ¶
- Constants
- func CertOpts(certFile, keyFile, domain string) opts
- func CreateDevCertKey() (certFile, keyFile string)
- func DevOpts() opts
- func LetsEncryptOpts(email, domain string) opts
- func NewMux(l log.Logger, opt middleware.Opts, rts Routes) *mux
- func NewOpts(port uint16, readHeaderTimeout time.Duration, readTimeout time.Duration, ...) opts
- func NewRoute(pattern string, method string, handler http.HandlerFunc) route
- func Run(h http.Handler, o opts, l log.Logger) error
- type Routes
Constants ¶
const ( MethodAll = "ALL" MethodGet = http.MethodGet MethodHead = http.MethodHead MethodPost = http.MethodPost MethodPut = http.MethodPut MethodPatch = http.MethodPatch MethodDelete = http.MethodDelete MethodConnect = http.MethodConnect MethodOptions = http.MethodOptions MethodTrace = http.MethodTrace )
Variables ¶
This section is empty.
Functions ¶
func CertOpts ¶
func CertOpts(certFile, keyFile, domain string) opts
CertOpts returns a new opts that has sensible defaults given certFile & keyFile.
func CreateDevCertKey ¶
func CreateDevCertKey() (certFile, keyFile string)
CreateDevCertKey generates and saves(to disk) a certifiate and key that can be used to configure a tls server. This is only meant to be used for development/local settings. The certificate is self-signed & a best effort is made to add its CA to the OS trust store.
func DevOpts ¶
func DevOpts() opts
DevOpts returns a new opts that has sensible defaults for tls, especially for dev environments.
func LetsEncryptOpts ¶
func LetsEncryptOpts(email, domain string) opts
LetsEncryptOpts returns a new opts that procures certificates from Letsencrypt.
func NewMux ¶
func NewMux(l log.Logger, opt middleware.Opts, rts Routes) *mux
NewMux creates a new mux.
func NewOpts ¶
func NewOpts( port uint16, readHeaderTimeout time.Duration, readTimeout time.Duration, writeTimeout time.Duration, handlerTimeout time.Duration, idleTimeout time.Duration, certFile string, keyFile string, email string, domain string, ) opts
NewOpts returns a new opts. If certFile is a non-empty string, this will enable tls from certificates found on disk. If email is a non-empty string, this will enable tls from certificates procured from letsencrypt. domain can be an exact domain, subdomain or wildcard.
func NewRoute ¶
func NewRoute( pattern string, method string, handler http.HandlerFunc, ) route
NewRoute creates a new route.
func Run ¶
Run listens on a network address and then calls Serve to handle requests on incoming connections. It sets up a server with the parameters provided by o.
The server shuts down cleanly after receiving any terminating signal. If the opts supplied include a certificate and key, the server will accept https traffic and also automatically handle http->https redirect.