web

package
v0.0.0-...-cc07b41 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const KeyValues ctxKey = 1

KeyValues is how request values or stored/retrieved.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	*httptreemux.TreeMux
	// 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 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(verb, path string, handler Handler, mw ...Middleware)

Handle is our mechanism for mounting Handlers for a given HTTP verb and path pair, this makes for really easy, convenient routing.

func (*App) ServeHTTP

func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface. It overrides the ServeHTTP of the embedded TreeMux by using the ochttp.Handler instead. That Handler wraps the TreeMux handler so the routes are served.

func (*App) SignalShutdown

func (a *App) SignalShutdown()

SignalShutdown is used to gracefully shutdown the app when an integrity issue is identified.

type Handler

type Handler func(ctx context.Context, w http.ResponseWriter, r *http.Request, params map[string]string) error

A Handler is a type that handles an http request within our own little mini framework.

type Middleware

type Middleware func(Handler) Handler

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.

type Values

type Values struct {
	TraceID    string
	Now        time.Time
	StatusCode int
}

Values represent state for each request.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL