Documentation ¶
Overview ¶
Package web contains a small web framework extension.
Index ¶
- func Decode(r *http.Request, v Decoder) error
- func GetTraceID(ctx context.Context) string
- func Param(r *http.Request, key string) string
- type App
- func (a *App) EnableCORS(origins []string)
- func (a *App) HandlerFunc(method string, group string, path string, handlerFunc HandlerFunc, ...)
- func (a *App) HandlerFuncNoMid(method string, group string, path string, handlerFunc HandlerFunc)
- func (a *App) RawHandlerFunc(method string, group string, path string, rawHandlerFunc http.HandlerFunc, ...)
- func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type Decoder
- type Encoder
- type HandlerFunc
- type Logger
- type MidFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode reads the body of an HTTP request and decodes the body into the specified data model. If the data model implements the validator interface, the method will be called.
func GetTraceID ¶
GetTraceID returns the trace id from the context.
Types ¶
type App ¶
type App struct {
// 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.
func (*App) EnableCORS ¶
EnableCORS enables CORS preflight requests to work in the middleware. It prevents the MethodNotAllowedHandler from being called. This must be enabled for the CORS middleware to work.
func (*App) HandlerFunc ¶
func (a *App) HandlerFunc(method string, group string, path string, handlerFunc HandlerFunc, mw ...MidFunc)
HandlerFunc sets a handler function for a given HTTP method and path pair to the application server mux.
func (*App) HandlerFuncNoMid ¶
func (a *App) HandlerFuncNoMid(method string, group string, path string, handlerFunc HandlerFunc)
HandlerFuncNoMid sets a handler function for a given HTTP method and path pair to the application server mux. Does not include the application middleware or OTEL tracing.
func (*App) RawHandlerFunc ¶
func (a *App) RawHandlerFunc(method string, group string, path string, rawHandlerFunc http.HandlerFunc, mw ...MidFunc)
RawHandlerFunc sets a raw handler function for a given HTTP method and path pair to the application server mux.
func (*App) ServeHTTP ¶
func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the http.Handler interface. It's the entry point for all http traffic and allows the opentelemetry mux to run first to handle tracing. The opentelemetry mux then calls the application mux to handle application traffic. This was set up on line 44 in the NewApp function.
type Encoder ¶
Encoder defines behavior that can encode a data model and provide the content type for that encoding.
type HandlerFunc ¶
HandlerFunc represents a function that handles a http request within our own little mini framework.
type MidFunc ¶
type MidFunc func(handler HandlerFunc) HandlerFunc
MidFunc is a handler function designed to run code before and/or after another Handler. It is designed to remove boilerplate or other concerns not direct to any given app Handler.