Documentation ¶
Index ¶
- func Decode(r *http.Request, val any) error
- func GetTime(ctx context.Context) time.Time
- func GetTraceID(ctx context.Context) string
- func IsError(err error) bool
- func IsShutdown(err error) bool
- func NewError(err error, status int) error
- func NewErrorS(msg string, status int) error
- func NewShutdownError(message string) error
- func Param(r *http.Request, name string) string
- func RespondJson(ctx context.Context, w http.ResponseWriter, data any, statusCode int) error
- func RespondJsonPlain(ctx context.Context, w http.ResponseWriter, data any, statusCode int) error
- func SetStatusCode(ctx context.Context, statusCode int)
- type App
- func (a *App) AddGroup(rg ...RouteGroup)
- func (a *App) GET(path string, handler Handler, mw ...Middleware)
- func (a *App) Handle(method string, path string, handler Handler, mw ...Middleware)
- func (a *App) PATCH(path string, handler Handler, mw ...Middleware)
- func (a *App) POST(path string, handler Handler, mw ...Middleware)
- func (a *App) SignalShutdown()
- type Error
- type ErrorDocument
- type Handler
- type Middleware
- type RouteGroup
- type Values
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetTraceID ¶
GetTraceID returns the trace id from the context.
func IsShutdown ¶
IsShutdown checks to see if the shutdown error is contained in the specified error value.
func NewError ¶
NewError wraps a provided error with an HTTP status code. This function should be used as fallback when handlers encounter expected errors i.e., if it was not a validation error, auth error, or db error, etc.
func NewShutdownError ¶
NewShutdownError returns an error that causes the framework to signal a graceful shutdown.
func RespondJson ¶
RespondJson wraps the return the value as {data: value} according to the status code and sends json to the response writer
func RespondJsonPlain ¶
RespondJsonPlain sends json to the response writer without wrapping
func SetStatusCode ¶
SetStatusCode sets the status code back into the context.
Types ¶
type App ¶
type App struct { *httptreemux.ContextMux // contains filtered or unexported fields }
App is the entrypoint into our application and what configures our context object for each of our http handlers.
func NewApp ¶
func NewApp(shutdown chan os.Signal, mw ...Middleware) *App
NewApp creates an App value that handle a set of routes for the application.
func (*App) AddGroup ¶
func (a *App) AddGroup(rg ...RouteGroup)
AddGroup accepts a list of RouteGroup and registers them with the App
func (*App) Handle ¶
func (a *App) Handle(method string, path string, handler Handler, mw ...Middleware)
func (*App) SignalShutdown ¶
func (a *App) SignalShutdown()
SignalShutdown is used to gracefully shut down the app when an integrity issue is identified.
type Error ¶
Error is used to pass an error during the request through the application with web specific context.
type ErrorDocument ¶
type ErrorDocument struct { Error string `json:"error"` Fields map[string]string `json:"fields,omitempty"` }
ErrorDocument is the form used for API responses from failures in the API.
type Handler ¶
A Handler is a type that handles an http request within App different than the http.Handler in that it accepts context as the first parameter and returns an error
type Middleware ¶
Middleware is a function designed to run some code before and/or after another Handler.
type RouteGroup ¶
type RouteGroup interface {
Register(*App)
}
RouteGroup defines the behavior that binds routes to App