Documentation ¶
Index ¶
- type Binding
- type MiddlewareFunc
- type Resource
- type Response
- type RouteFunc
- type Router
- func (r *Router) AddMiddleware(fn []MiddlewareFunc) *Router
- func (r *Router) Base(prefix string) *Router
- func (r *Router) Connect(route string, f http.Handler, middleware ...MiddlewareFunc) *Router
- func (r Router) DefaultServer() *http.Server
- func (r *Router) Delete(route string, f http.Handler, middleware ...MiddlewareFunc) *Router
- func (r *Router) Get(route string, f http.Handler, middleware ...MiddlewareFunc) *Router
- func (r *Router) Head(route string, f http.Handler, middleware ...MiddlewareFunc) *Router
- func (r *Router) Merge(routers ...*Router) *Router
- func (r *Router) Options(route string, f http.Handler, middleware ...MiddlewareFunc) *Router
- func (r *Router) Patch(route string, f http.Handler, middleware ...MiddlewareFunc) *Router
- func (r *Router) PathParam(req *http.Request, key string) interface{}
- func (r *Router) Post(route string, f http.Handler, middleware ...MiddlewareFunc) *Router
- func (r *Router) Put(route string, f http.Handler, middleware ...MiddlewareFunc) *Router
- func (r *Router) QueryParam(req *http.Request, key string) interface{}
- func (r *Router) Resource(prefix string, resource Resource)
- func (r Router) ServeHTTP(rw http.ResponseWriter, req *http.Request)
- func (r *Router) SetDIContainer(c *ghastContainer.Container)
- func (r *Router) Trace(route string, f http.Handler, middleware ...MiddlewareFunc) *Router
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Binding ¶
type Binding struct {
// contains filtered or unexported fields
}
Binding maps a url pattern to an HTTP handler
type MiddlewareFunc ¶
MiddlewareFunc type alias for a function that takes in a http.Handler and returns an HTTP Handler
func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { curContext := req.Context() req = req.Clone(context.WithValue(curContext, KEY, "BAR")) next.ServeHTTP(w, req) }) }
type Resource ¶
type Resource interface { GetName() string Index(req *http.Request) (Response, error) Get(req *http.Request) (Response, error) Create(req *http.Request) (Response, error) Update(req *http.Request) (Response, error) Delete(req *http.Request) (Response, error) }
Resource an interface that includes functionality intended to be used with fetching a list of items, getting a single item, creating a single item, updating a single item, and deleting a single item
type RouteFunc ¶
RouteFunc a type alias for controller actions Controllers only have the request exposed to them as the response writer is handled by the Ghast framework.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router struct models our routes to match off of and their behavior
func (*Router) AddMiddleware ¶
func (r *Router) AddMiddleware(fn []MiddlewareFunc) *Router
AddMiddleware registers a new global middleware within the router global middlewares will be called on any route that matches a route binding
func (Router) DefaultServer ¶
DefaultServer is an optional method to help get a preconfigured server with the router bound as the handler and some sensible defaults
func (*Router) QueryParam ¶
PathParam Get a Path Parameter from a given request and key
func (*Router) Resource ¶
Resource takes in a Controller Resource and generates Index, Get, Create, Delete and Update routes for that resource. Prefix is a string for any scoping or namespacing for the resource For example, you can pass "/v1/" as a Prefix for a Resource where getName returns "user" which would create the following routes: GET /v1/user GET /v1/user/:id POST /v1/user DELETE /v1/user/:id UPDATE /v1/user/:id
func (Router) ServeHTTP ¶
func (r Router) ServeHTTP(rw http.ResponseWriter, req *http.Request)
ServeHTTP allows the router to adhere to the handler func requirements Delegates requests to provided routes
func (*Router) SetDIContainer ¶
func (r *Router) SetDIContainer(c *ghastContainer.Container)
SetDIContainer sets up the DI container that this router will use. The provided DI container will be available in all controllers via context (or controller helpers)