Documentation ¶
Overview ¶
Package web contains a small web framework extension.
Index ¶
- func GetTime(ctx context.Context) time.Time
- func GetTraceID(ctx context.Context) string
- func IsShutdown(err error) bool
- func NewShutdownError(message string) error
- func Respond(ctx context.Context, w http.ResponseWriter, data any, statusCode int) error
- func SetStatusCode(ctx context.Context, statusCode int)
- type App
- type Handler
- type Middleware
- 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 NewShutdownError ¶
NewShutdownError returns an error that causes the framework to signal a graceful shutdown.
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. Feel free to add any configuration data/logic on this App struct. we provide some middleware at application level - e.g., logging
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) Handle ¶
func (a *App) Handle(method string, path string, handler Handler, mw ...Middleware)
Handle sets a handler function for a given HTTP method and path pair to the application server mux. Note that this way we override the default implementation of Handle function present in Context.Mux Note that we include Route specific middleware [e.g., auth for some pathes]
func (*App) SignalShutdown ¶
func (a *App) SignalShutdown()
SignalShutdown is used to gracefully shut down the app when an integrity issue is identified.
type Handler ¶
A Handler is a type that handles a http request within our own little mini framework.
type Middleware ¶
Middleware is a function designed to run some code before and/or after another Handler. It is designed to remove boilerplate or other concerns not direct to any given Handler.