Documentation ¶
Overview ¶
Package http provides easy access to HcNet's best practices for building http servers. The primary method to use is `Serve`, which sets up an server that can support http/2 and can gracefully quit after receiving a SIGINT signal.
Index ¶
- Constants
- func HeadersMiddleware(headers stdhttp.Header, ignoredPrefixes ...string) func(next stdhttp.Handler) stdhttp.Handler
- func LoggingMiddleware(next stdhttp.Handler) stdhttp.Handler
- func NewAPIMux(behindProxy bool) *chi.Mux
- func NewMux(behindProxy bool) *chi.Mux
- func Run(conf Config)
- func StripTrailingSlashMiddleware(ignoredPrefixes ...string) func(next stdhttp.Handler) stdhttp.Handler
- type Config
- type SimpleHTTPClientInterface
Constants ¶
const DefaultListenAddr = "0.0.0.0:8080"
DefaultListenAddr represents the default address and port on which a server will listen, provided it is not overridden by setting the `ListenAddr` field on a `Config` struct.
const DefaultShutdownGracePeriod = 10 * time.Second
DefaultShutdownGracePeriod represents the default time in which the running process will allow outstanding http requests to complete before aborting them. It will be used when a grace period of 0 is used, which normally signifies "no timeout" to our graceful shutdown package. We choose not to provide a "no timeout" mode at present. Feel free to set the value to a year or something if you need a timeout that is effectively "no timeout"; We believe that most servers should use a sane timeout and prefer one for the default configuration.
Variables ¶
This section is empty.
Functions ¶
func HeadersMiddleware ¶
func HeadersMiddleware(headers stdhttp.Header, ignoredPrefixes ...string) func(next stdhttp.Handler) stdhttp.Handler
HeadersMiddleware sends headers
func LoggingMiddleware ¶
LoggingMiddleware is a middleware that logs requests to the logger.
func NewAPIMux ¶
NewAPIMux returns a new server mux configured with the common defaults used for a web API in hcnet.
func NewMux ¶
NewMux returns a new server mux configured with the common defaults used across all hcnet services.
func Run ¶
func Run(conf Config)
Run starts an http server using the provided config struct.
This method configures the process to listen for termination signals (SIGINT and SIGTERM) to trigger a graceful shutdown by way of the graceful package (https://github.com/tylerb/graceful).
Types ¶
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package httptest enhances the stdlib net/http/httptest package by integrating it with gopkg.in/gavv/httpexpect.v1, reducing the boilerplate needed for http tests.
|
Package httptest enhances the stdlib net/http/httptest package by integrating it with gopkg.in/gavv/httpexpect.v1, reducing the boilerplate needed for http tests. |
Package mutil contains various functions that are helpful when writing http middleware.
|
Package mutil contains various functions that are helpful when writing http middleware. |