Documentation ¶
Overview ¶
Package http provides easy access to AiBlocks'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 ¶
- func EqualFileSystems(fs, otherFS http.FileSystem, currentPath string) bool
- func HeadersMiddleware(headers stdhttp.Header, ignoredPrefixes ...string) func(next stdhttp.Handler) stdhttp.Handler
- func LoggingMiddleware(next stdhttp.Handler) stdhttp.Handler
- func NewAPIMux(l *log.Entry) *chi.Mux
- func NewMux(l *log.Entry) *chi.Mux
- func Run(conf Config)
- func SetLoggerMiddleware(l *log.Entry) func(stdhttp.Handler) stdhttp.Handler
- func StripTrailingSlashMiddleware(ignoredPrefixes ...string) func(next stdhttp.Handler) stdhttp.Handler
- type Config
- type SimpleHTTPClientInterface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EqualFileSystems ¶
func EqualFileSystems(fs, otherFS http.FileSystem, currentPath string) bool
EqualFileSystems traverses two http.FileSystem instances and returns true if they are equal
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 aiblocks.
func NewMux ¶
NewMux returns a new server mux configured with the common defaults used across all aiblocks 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).
func SetLoggerMiddleware ¶
SetLogger is a middleware that sets a logger on the context.
Types ¶
type Config ¶
type Config struct { Handler stdhttp.Handler ListenAddr string TLS *config.TLS ShutdownGracePeriod time.Duration ReadTimeout time.Duration WriteTimeout time.Duration IdleTimeout time.Duration OnStarting func() OnStopping func() OnStopped func() }
Config represents the configuration of an http server that can be provided to `Run`.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package httpauthz contains helper functions for parsing the 'Authorization' header in HTTP requests.
|
Package httpauthz contains helper functions for parsing the 'Authorization' header in HTTP requests. |
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. |