web

package
v0.0.0-...-d6b3ade Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

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.

func Shutdown

func Shutdown(log logrus.FieldLogger, sig chan os.Signal, stopped chan bool, done chan bool, timeout time.Duration, shutdowners ...Shutdowner)

Shutdown gracefully shuts down an HTTP server and app.

func URLParam

func URLParam(r *http.Request, key string) string

URLParam wraps chi.URLParam.

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

func (a *App) Bootstrap(h Handler) Handler

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.

func (*App) ServeHTTP

func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler, proxying the incoming request to the Router.

func (*App) Shutdown

func (a *App) Shutdown(ctx context.Context) error

Shutdown closes any resources that we might want to responsibly close before the app is terminated.

type Handler

Handler is a function that takes an HTTP request and responds appropriately.

func Shim

func Shim(h http.Handler) Handler

type Middleware

type Middleware func(Handler) Handler

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.

func (Router) Put

func (r Router) Put(pattern string, handler Handler, rmws ...Middleware)

Put attaches a PUT Handler to the provided pattern with the provided middlewares.

func (Router) Route

func (r Router) Route(pattern string, f func(Router), rmws ...Middleware)

Route allows the caller to take over a subset of routes in the global router and attach routes (using the provided function) and middleware.

type ShutdownCtxFunc

type ShutdownCtxFunc func(context.Context) error

type ShutdownFunc

type ShutdownFunc func() error

func (ShutdownFunc) Shutdown

func (f ShutdownFunc) Shutdown() error

type Shutdowner

type Shutdowner interface {
	// contains filtered or unexported methods
}

Directories

Path Synopsis
cors
Package cors is ported from github.com/go-chi/cors to implement CORS middleware for web.Handler.
Package cors is ported from github.com/go-chi/cors to implement CORS middleware for web.Handler.

Jump to

Keyboard shortcuts

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