Documentation
¶
Overview ¶
Package http provide common utilities when deploying a production HTTP(S) service.
The main element of the package is the "Server" type. Use it to easily create and manage an HTTP(S) server instance.
// Server options options := []Option{ WithPort(8080), WithIdleTimeout(5 * time.Second), WithHandler(mux), } // Create and start the server in the background server, _ := NewServer(options...) go func() { _ = server.Start() }() // When no longer required, gracefully stop the server _ = server.Stop(true)
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
Option allows adjusting server settings following a functional pattern.
func WithHandler ¶
WithHandler sets the HTTP handler used by the server.
func WithIdleTimeout ¶
WithIdleTimeout sets the maximum amount of time to wait for the next request when "keep-alive" is enabled. You can use `0` to disable all the server's timeouts.
func WithMiddleware ¶
WithMiddleware register the provided middleware to customize/extend the processing of HTTP requests. When applying middleware the ordering is very important, in this case it will be applied in the same order provided. For example:
Use(foo bar baz)
Will be applied as:
baz( bar( foo(handler) ) )
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server provides the main HTTP(S) service provider.
func NewServer ¶
NewServer returns a new read-to-use server instance adjusted with the provided configuration options.
Example ¶
// Server options options := []Option{ WithHandler(mux), WithPort(8080), WithIdleTimeout(5 * time.Second), WithMiddleware( mwRecover.Handler(), mwProxy.Handler(), mwGzip.Handler(9), ), } // Create and start the server in the background server, _ := NewServer(options...) go func() { _ = server.Start() }() // When no longer required, gracefully stop the server _ = server.Stop(true)
Output:
type TLS ¶
type TLS struct { // Server certificate, PEM-encoded. Cert []byte // Server private key, PEM-encoded. PrivateKey []byte // List of ciphers to allow. SupportedCiphers []uint16 // Server preferred curves configuration. PreferredCurves []tls.CurveID // Whether to include system CAs. IncludeSystemCAs bool // Custom certificate authorities to include when accepting TLS connections. CustomCAs [][]byte }
TLS defines available settings when enabling secure TLS communications.