Documentation ¶
Overview ¶
Package server provides simple utilities to create new http.Server.
Index ¶
- func New(options ...ServerOption) (*http.Server, error)
- type ServerOption
- func WithBasicAuth(user string, password string, h http.Handler) ServerOption
- func WithGracefulShutdown(done <-chan struct{}, quit chan<- struct{}) ServerOption
- func WithHandler(handler http.Handler) ServerOption
- func WithIdleTimeout(timeout time.Duration) ServerOption
- func WithListenAddr(addr string) ServerOption
- func WithReadTimeout(timeout time.Duration) ServerOption
- func WithWriteTimeout(timeout time.Duration) ServerOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(options ...ServerOption) (*http.Server, error)
New can receive zero or multiple ServerOption and returns a new http.Server with these options applied. It returns an error if there is no server.Handler specified or if the server.Addr is an empty string after having applied the received options.
Types ¶
type ServerOption ¶
ServerOption defines an option to a new http.Server.
func WithBasicAuth ¶
func WithBasicAuth(user string, password string, h http.Handler) ServerOption
WithBasicAuth receives an user, a password and a http.Handler and returns a ServerOption that applies it to the http.Server.
func WithGracefulShutdown ¶
func WithGracefulShutdown(done <-chan struct{}, quit chan<- struct{}) ServerOption
WithGracefulShutdown receives a done and a quit chan and returns a ServerOption that initializes a goroutine that listens to the done chan to try to shutdown the http.Server gracefully.
func WithHandler ¶
func WithHandler(handler http.Handler) ServerOption
WithHandler receives an http.Handler and returns a ServerOption that applies it to the http.Server.
func WithIdleTimeout ¶
func WithIdleTimeout(timeout time.Duration) ServerOption
WithIdleTimeout receives a timeout and returns a ServerOption that applies it to the http.Server.
func WithListenAddr ¶
func WithListenAddr(addr string) ServerOption
WithListenAddr receives an address and returns a ServerOption that applies it to the http.Server.
func WithReadTimeout ¶
func WithReadTimeout(timeout time.Duration) ServerOption
WithReadTimeout receives a timeout and returns a ServerOption that applies it to the http.Server.
func WithWriteTimeout ¶
func WithWriteTimeout(timeout time.Duration) ServerOption
WithWriteTimeout receives a timeout and returns a ServerOption that applies it to the http.Server.