Documentation ¶
Overview ¶
Package web contains a small web framework extension.
Index ¶
- func InitContextValues(ctx context.Context, v *CtxValues) context.Context
- func IsShutdown(err error) bool
- func NewRequestError(errMessage string, status int) error
- func NewShutdownError(message string) error
- func Respond(ctx context.Context, w http.ResponseWriter, data interface{}, statusCode int) error
- func SetStatusCode(ctx context.Context, statusCode int) error
- type API
- type App
- type CtxValues
- type FileReader
- type Handler
- type Middleware
- type RequestError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitContextValues ¶
InitContextValues initializes the CtxValues in the context with the given values and return the updated context.
func IsShutdown ¶
IsShutdown checks to see if the shutdown error is contained in the specified error value.
func NewRequestError ¶
NewRequestError creates a new RequestError with the provided error and HTTP status code.
func NewShutdownError ¶
NewShutdownError returns an error that causes the framework to signal a graceful shutdown.
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API represents a web application that hosts a REST API.
func NewAPI ¶
func NewAPI(shutdown chan os.Signal, middlewares ...Middleware) *API
NewAPI creates an API that handle a set of routes for the application.
func (*API) Register ¶
func (a *API) Register(method, group, path string, handler Handler, middlewares ...Middleware)
Register mounts the provided handler to the provided path creating a route.
func (*API) ServeHTTP ¶
func (a *API) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the http.Handler interface.
func (*API) SignalShutdown ¶
func (a *API) SignalShutdown()
SignalShutdown is used to gracefully shutdown the API.
type FileReader ¶
type Handler ¶
type Handler func(context.Context, http.ResponseWriter, *http.Request, httprouter.Params) error
Handler extends the http.HandlerFunc buy adding a context, params and an error to return.
type Middleware ¶
Middleware is a func type that wraps around handlers. These funcs or executed before or after the handler.
type RequestError ¶
RequestError represents an error with an HTTP status code.
func (*RequestError) Error ¶
func (r *RequestError) Error() string
Error implements the error interface.