Documentation
¶
Index ¶
- Constants
- func Run(ctx context.Context, logger *zap.Logger, listener net.Listener, ...) (retErr error)
- type HTTPHandlerMapperOption
- type Mapper
- type MapperFunc
- type RunOption
- type Runner
- type RunnerOption
- func RunnerWithHealth() RunnerOption
- func RunnerWithMaxBodySize(maxBodySize int64) RunnerOption
- func RunnerWithMiddlewares(middlewares ...func(http.Handler) http.Handler) RunnerOption
- func RunnerWithReadHeaderTimeout(readHeaderTimeout time.Duration) RunnerOption
- func RunnerWithShutdownTimeout(shutdownTimeout time.Duration) RunnerOption
- func RunnerWithSilentEndpoints(silentEndpoints ...string) RunnerOption
- func RunnerWithTLSConfig(tlsConfig *tls.Config) RunnerOption
- func RunnerWithWalkFunc(walkFunc chi.WalkFunc) RunnerOption
Constants ¶
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 ¶ added in v1.8.0
func Run( ctx context.Context, logger *zap.Logger, listener net.Listener, handler http.Handler, options ...RunOption, ) (retErr 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 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 ¶
Mapper initializes a Router.
func MapperWithMiddlewares ¶ added in v1.8.0
func MapperWithMiddlewares(mapper Mapper, middlewares chi.Middlewares) Mapper
MapperWithMiddlewares rewrites the Map function of the Mapper to call the provided middlewares inside a chi Group before mapping
func NewHTTPHandlerMapper ¶
func NewHTTPHandlerMapper( handler http.Handler, options ...HTTPHandlerMapperOption, ) Mapper
NewHTTPHandlerMapper returns a new Mapper for the http.Handler.
type MapperFunc ¶
MapperFunc is a function for a Mapper
type RunOption ¶ added in v1.8.0
type RunOption = RunnerOption
RunOption is an option for a new Run.
func RunWithReadHeaderTimeout ¶ added in v1.8.0
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 ¶ added in v1.8.0
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 ¶ added in v1.8.0
RunWithTLSConfig returns a new RunOption that uses the given tls.Config.
The default is to use no TLS.
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.
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 RunnerWithSilentEndpoints ¶ added in v1.8.0
func RunnerWithSilentEndpoints(silentEndpoints ...string) RunnerOption
RunnerWithSilentEndpoints returns a new RunnerOption that disables logging from the provided endpoints.
The default is to not silence any endpoints.
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.