Documentation ¶
Index ¶
- func ListenAndServe(ctx context.Context, address string, handler http.HandlerFunc) error
- func MiddlewareRecover(callbacks ...MiddlewareRecoverFunc) func(http.Handler) http.Handler
- func NewListener(ctx context.Context, address string, opts ...ListenerOption) (net.Listener, error)
- func NewServer(handler http.HandlerFunc, opts ...ServerOption) *http.Server
- func Serve(ctx context.Context, s *http.Server, l net.Listener, ...) error
- type ListenerOption
- type MiddlewareRecoverFunc
- type ServerOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListenAndServe ¶ added in v1.1.0
ListenAndServe is a shortcut for NewListener and Serve.
func MiddlewareRecover ¶ added in v1.1.0
func MiddlewareRecover(callbacks ...MiddlewareRecoverFunc) func(http.Handler) http.Handler
MiddlewareRecover is a middleware that recover requests from a panic.
func NewListener ¶
NewListener creates a new listener.
func NewServer ¶
func NewServer(handler http.HandlerFunc, opts ...ServerOption) *http.Server
NewServer returns a configured http server with robust defaults.
func Serve ¶ added in v1.1.0
func Serve(ctx context.Context, s *http.Server, l net.Listener, shutdownTimeout time.Duration) error
Serve serves the server through the provided listener. On context cancellation, the server tries to gracefully shut down for as long as shutdownTimeout. Once this timeout is reached, the server is stopped, any way.
Types ¶
type ListenerOption ¶
type ListenerOption func(*listenerOptions) error
ListenerOption defines options applier for the listener.
func ListenWithIntermediateTLSConfig ¶ added in v1.1.0
func ListenWithIntermediateTLSConfig(certFile, keyFile string) ListenerOption
ListenWithIntermediateTLSConfig sets the tls configuration for tls.NewListener. "Intermediate" is defined based on this website: https://wiki.mozilla.org/Security/Server_Side_TLS.
func ListenWithKeepAlive ¶
func ListenWithKeepAlive(keepAlive time.Duration) ListenerOption
ListenWithKeepAlive sets keepalive period.
func ListenWithNetwork ¶
func ListenWithNetwork(network string) ListenerOption
ListenWithNetwork sets the network option for net.Listen().
func ListenWithTLSConfig ¶
func ListenWithTLSConfig(cfg *tls.Config) ListenerOption
ListenWithTLSConfig sets the tls configuration for tls.NewListener.
func ListenWithoutKeepAlive ¶
func ListenWithoutKeepAlive() ListenerOption
ListenWithoutKeepAlive disables the keepalive on the listener.
type MiddlewareRecoverFunc ¶ added in v1.1.0
type MiddlewareRecoverFunc func(rw http.ResponseWriter, r *http.Request, reason any)
MiddlewareRecoverFunc is the signature of the callback called each time the request panics.
type ServerOption ¶
type ServerOption func(*serverOptions)
ServerOption defines options applier for the server.
func ServerWithErrorLogger ¶ added in v1.1.0
func ServerWithErrorLogger(logger *log.Logger) ServerOption
ServerWithErrorLogger sets the provider logger to be used for errors in the http server.