httpserver

package
v0.0.0-...-26f4575 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultShutdownTimeout is the default shutdown timeout.
	DefaultShutdownTimeout = 10 * time.Second
	// DefaultReadHeaderTimeout is the default read header timeout.
	DefaultReadHeaderTimeout = 30 * time.Second
	// DefaultIdleTimeout is the amount of time an HTTP/2 connection can be idle.
	DefaultIdleTimeout = 3 * time.Minute
)

Variables

This section is empty.

Functions

func Run

func Run(
	ctx context.Context,
	logger *zap.Logger,
	listener net.Listener,
	handler http.Handler,
	options ...RunOption,
) error

Run will start a HTTP server listening on the provided listener and serving the provided handler. This call is blocking and the run is cancelled when the input context is cancelled, the listener is closed upon return.

The Run function can be configured further by passing a variety of options.

Types

type RunOption

type RunOption func(*runner)

RunOption is an option for a new Run.

func RunWithReadHeaderTimeout

func RunWithReadHeaderTimeout(readHeaderTimeout time.Duration) RunOption

RunWithReadHeaderTimeout returns a new RunOption that uses the given read header timeout.

The default is to use DefaultReadHeaderTimeout. If readHeaderTimeout is 0, no read header timeout will be used.

func RunWithShutdownTimeout

func RunWithShutdownTimeout(shutdownTimeout time.Duration) RunOption

RunWithShutdownTimeout returns a new RunOption that uses the given shutdown timeout.

The default is to use DefaultShutdownTimeout. If shutdownTimeout is 0, no graceful shutdown will be performed.

func RunWithTLSConfig

func RunWithTLSConfig(tlsConfig *tls.Config) RunOption

RunWithTLSConfig returns a new RunOption that uses the given tls.Config.

The default is to use no TLS.

func RunWithWalkFunc

func RunWithWalkFunc(walkFunc chi.WalkFunc) RunOption

RunWithWalkFunc returns a new RunOption that runs chi.Walk to walk the handler after all middlewares and routes have been mounted, but before the server is started. The walkFunc will only be called if the handler passed to Run is a chi.Routes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL