httpserver

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2022 License: Apache-2.0 Imports: 13 Imported by: 1

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

This section is empty.

Types

type HTTPHandlerMapperOption

type HTTPHandlerMapperOption func(*httpHandlerMapper)

HTTPHandlerMapperOption is an option for a new HTTPHandlerMapper.

func HTTPHandlerMapperWithPrefix

func HTTPHandlerMapperWithPrefix(prefix string) HTTPHandlerMapperOption

HTTPHandlerMapperWithPrefix returns a new HTTPHandlerMapperOption that uses the prefix.

type Mapper

type Mapper interface {
	Map(chi.Router) error
}

Mapper initializes a Router.

func NewHTTPHandlerMapper

func NewHTTPHandlerMapper(
	handler http.Handler,
	options ...HTTPHandlerMapperOption,
) Mapper

NewHTTPHandlerMapper returns a new Mapper for the http.Handler.

type MapperFunc

type MapperFunc func(chi.Router) error

MapperFunc is a function for a Mapper

func (MapperFunc) Map

func (m MapperFunc) Map(router chi.Router) error

Map implements Mapper.

type Runner

type Runner interface {
	// Run runs the router.
	//
	// Blocking.
	// The runner is cancelled when the input context is cancelled.
	// The listener is closed upon return.
	//
	// Response write errors are logged. Response write errors can be ignored.
	//
	// Can be called multiple times, resulting in different runs.
	Run(ctx context.Context, listener net.Listener, mappers ...Mapper) error
}

Runner is a runner.

func NewRunner

func NewRunner(logger *zap.Logger, options ...RunnerOption) Runner

NewRunner returns a new Runner.

type RunnerOption

type RunnerOption func(*runner)

RunnerOption is an option for a new Runner.

func RunnerWithHealth

func RunnerWithHealth() RunnerOption

RunnerWithHealth returns a new RunnerOption that turns a health check endpoint on at /health.

The default is to not turn on health.

func RunnerWithMaxBodySize

func RunnerWithMaxBodySize(maxBodySize int64) RunnerOption

RunnerWithMaxBodySize returns a new RunnerOption that sets the max size of incoming request body.

The default is to not limit body size.

func RunnerWithMiddlewares

func RunnerWithMiddlewares(middlewares ...func(http.Handler) http.Handler) RunnerOption

RunnerWithMiddlewares returns a new RunnerOption that use middlewares when the Runner Run.

func RunnerWithReadHeaderTimeout

func RunnerWithReadHeaderTimeout(readHeaderTimeout time.Duration) RunnerOption

RunnerWithReadHeaderTimeout returns a new RunnerOption 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 RunnerWithShutdownTimeout

func RunnerWithShutdownTimeout(shutdownTimeout time.Duration) RunnerOption

RunnerWithShutdownTimeout returns a new RunnerOption that uses the given shutdown timeout.

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

func RunnerWithTLSConfig

func RunnerWithTLSConfig(tlsConfig *tls.Config) RunnerOption

RunnerWithTLSConfig returns a new RunnerOption that uses the given tls.Config.

The default is to use no TLS.

func RunnerWithWalkFunc

func RunnerWithWalkFunc(walkFunc chi.WalkFunc) RunnerOption

RunnerWithWalkFunc returns a new RunnerOption that runs chi.Walk to walk the router after all middlewares and routes have been mounted, but before the server is started.

Jump to

Keyboard shortcuts

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