Documentation ¶
Index ¶
- func HandlerFunc(h Handler, mws ...Middleware) http.HandlerFunc
- func Shutdown(log logrus.FieldLogger, sig chan os.Signal, stopped chan bool, done chan bool, ...)
- func URLParam(r *http.Request, key string) string
- type App
- func (a *App) Bootstrap(h Handler) Handler
- func (a *App) Health(ctx context.Context, log logrus.FieldLogger, w http.ResponseWriter, ...)
- func (a *App) Route(rs func(r Router), mws ...Middleware)
- func (a *App) RouteModule(m Module, mws ...Middleware)
- func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (a *App) Shutdown(ctx context.Context) error
- type Handler
- type Middleware
- type Module
- type Router
- func (r Router) Delete(pattern string, handler Handler, rmws ...Middleware)
- func (r Router) Get(pattern string, handler Handler, rmws ...Middleware)
- func (r Router) Mount(pattern string, handler Handler, rmws ...Middleware)
- func (r Router) Post(pattern string, handler Handler, rmws ...Middleware)
- func (r Router) Put(pattern string, handler Handler, rmws ...Middleware)
- func (r Router) Route(pattern string, f func(Router), rmws ...Middleware)
- type ShutdownCtxFunc
- type ShutdownFunc
- type Shutdowner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandlerFunc ¶
func HandlerFunc(h Handler, mws ...Middleware) http.HandlerFunc
HandlerFunc returns an http.HandlerFunc that wraps the provided middleware around the provided handler, suitable for passing into an http.Server.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App holds a Router for endpoints as well as a contextual logger.
func NewApp ¶
func NewApp(log *logrus.Logger, mws ...Middleware) *App
NewApp instanciates a new App, with the provided logger and global middleware.
func (*App) Bootstrap ¶
Bootstrap is middleware that initializes a new context.Context from the request context, and creates a new log entry for passing through the request. It should be the *first* middleware invoked.
func (*App) Health ¶
func (a *App) Health(ctx context.Context, log logrus.FieldLogger, w http.ResponseWriter, r *http.Request)
Health is a Handler checks the health of the App, emitting a 503 if not healthy.
func (*App) Route ¶
func (a *App) Route(rs func(r Router), mws ...Middleware)
Route allows the caller to set custom routes on the global scope, with the provided middleware.
func (*App) RouteModule ¶
func (a *App) RouteModule(m Module, mws ...Middleware)
RouteModule attaches the routes from the provided module to the app, with the provided middleware.
type Handler ¶
type Handler func(context.Context, logrus.FieldLogger, http.ResponseWriter, *http.Request)
Handler is a function that takes an HTTP request and responds appropriately.
type Middleware ¶
Middleware is a function that wraps a Handler with another.
type Module ¶
type Module interface { Healthy() error Route(Router, ...Middleware) }
Module is a set of endpoints that can be naturally grouped together. A module can evaluate its own health and can attach itself to a Router.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router wraps a chi.Router.
func (Router) Delete ¶
func (r Router) Delete(pattern string, handler Handler, rmws ...Middleware)
Delete attaches a DELETE handler to the provided pattern with the provided middlewares.
func (Router) Get ¶
func (r Router) Get(pattern string, handler Handler, rmws ...Middleware)
Get attaches a GET Handler to the provided pattern with the provided middlewares.
func (Router) Mount ¶
func (r Router) Mount(pattern string, handler Handler, rmws ...Middleware)
Mount attaches the provided http.Handler directly to the given pattern with the provided middlewares. This is useful for serving static files or embedding other APIs directly.
func (Router) Post ¶
func (r Router) Post(pattern string, handler Handler, rmws ...Middleware)
Post attaches a POST Handler to the provided pattern with the provided middlewares.
type ShutdownCtxFunc ¶
type ShutdownFunc ¶
type ShutdownFunc func() error
func (ShutdownFunc) Shutdown ¶
func (f ShutdownFunc) Shutdown() error
type Shutdowner ¶
type Shutdowner interface {
// contains filtered or unexported methods
}