Documentation ¶
Overview ¶
Package web contains a small web framework extension.
Index ¶
- func Decode(r *http.Request, val interface{}) error
- func GetTraceID(ctx context.Context) string
- func IsShutdown(err error) bool
- func NewShutdownError(message string) error
- func Param(r *http.Request, key string) string
- func Respond(ctx context.Context, w http.ResponseWriter, data interface{}, statusCode int) error
- func SetStatusCode(ctx context.Context, statusCode int) error
- type App
- type Handler
- type Middleware
- type Values
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode reads the body of an HTTP request looking for a JSON document. The body is decoded into the provided value.
If the provided value is a struct then it is checked for validation tags.
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. [PS] Helper function to check the type of the error (Assert)
func NewShutdownError ¶
NewShutdownError returns an error that causes the framework to signal a graceful shutdown. [PS] Factory function to create and return error
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
[PS] This struct represents a web application 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 NewApp ¶
func NewApp(shutdown chan os.Signal, mw ...Middleware) *App
NewApp creates an App value that handle a set of routes for the application. [PS] pass 0 to many middleware functions
func (*App) Handle ¶
[PS] This is the outer layer. Actual treemux handle will be inside it Handle sets a handler function for a given HTTP method and path pair to the application server mux. [PS] group can be used for versioning v1, v2
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 setup on line 58 in the NewApp function.
func (*App) SignalShutdown ¶
func (a *App) SignalShutdown()
SignalShutdown is used to gracefully shutdown the app when an integrity issue is identified.
type Handler ¶
[PS] This handler function is used to overcome the limitation of httptreemux handler. This will be inner layer of onion A Handler is a type that handles an http request within our own little mini framework.
type Middleware ¶
[PS] middleware is the different concentric rings around a Handler function 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.