ion: github.com/estebarb/ion/components/router Index | Files

package router

import "github.com/estebarb/ion/components/router"

Package router contains a flexible router, with integrated context management per request

Index

Package Files

router.go

func ContextFactory Uses

func ContextFactory() interface{}

ContextFactory returns a new instance of Path (the router only needs to store the matched arguments in the path)

type IPathParam Uses

type IPathParam interface {
    PathParams() map[string]string
    SetPathParams(values map[string]string)
}

IPathParam must be implemented by the context used by the application, in order to allow the Router to store the path arguments there

type Path Uses

type Path struct {
    Params map[string]string
}

Path contains the arguments extracted by the router from the request path

func (*Path) PathParams Uses

func (c *Path) PathParams() map[string]string

PathParams returns all the arguments matched in the path by the router

func (*Path) SetPathParams Uses

func (c *Path) SetPathParams(values map[string]string)

SetPathParams replaces the existing path params values with new ones

type Route Uses

type Route struct {
    // contains filtered or unexported fields
}

Route represents a Router matching rule, to be further refined.

func (*Route) Name Uses

func (r *Route) Name(name string) *Route

Name assigns an identifier to the Route. This allows to use RouteFor to construct a path that could match this rule.

type Router Uses

type Router struct {
    *reqctx.State
    // contains filtered or unexported fields
}

Router register routes to be matched and dispatches its corresponding handler. As the router accepts path arguments then it fills the context with the them.

func New Uses

func New(ContextFactory func() interface{}) *Router

New creates a new router, with the given ContextFactory

func NewDefault Uses

func NewDefault() *Router

NewDefault creates a new router, using router.ContextFactory for the context creation

func (*Router) Delete Uses

func (r *Router) Delete(path string, handler http.Handler) *Route

Delete register the handler in the router, after wrapping it with the middleware

func (*Router) DeleteFunc Uses

func (r *Router) DeleteFunc(path string, handler http.HandlerFunc) *Route

DeleteFunc register the handler in the router, after wrapping it with the middleware

func (*Router) Get Uses

func (r *Router) Get(path string, handler http.Handler) *Route

Get register the handler in the router, after wrapping it with the middleware

func (*Router) GetFunc Uses

func (r *Router) GetFunc(path string, handler http.HandlerFunc) *Route

GetFunc register the handler in the router, after wrapping it with the middleware

func (*Router) HandleFunc Uses

func (r *Router) HandleFunc(method string,
    path string,
    handler http.HandlerFunc) *Route

HandleFunc register a handler to be dispatched when a request matches with the method and the path.

func (*Router) Handler Uses

func (r *Router) Handler(method string,
    path string,
    handler http.Handler) *Route

Handler register a handler to be dispatched when a request matches with the method and the path.

func (*Router) Options Uses

func (r *Router) Options(path string, handler http.Handler) *Route

Options register the handler in the router, after wrapping it with the middleware

func (*Router) OptionsFunc Uses

func (r *Router) OptionsFunc(path string, handler http.HandlerFunc) *Route

OptionsFunc register the handler in the router, after wrapping it with the middleware

func (*Router) Patch Uses

func (r *Router) Patch(path string, handler http.Handler) *Route

Patch register the handler in the router, after wrapping it with the middleware

func (*Router) PatchFunc Uses

func (r *Router) PatchFunc(path string, handler http.HandlerFunc) *Route

PatchFunc register the handler in the router, after wrapping it with the middleware

func (*Router) Post Uses

func (r *Router) Post(path string, handler http.Handler) *Route

Post register the handler in the router, after wrapping it with the middleware

func (*Router) PostFunc Uses

func (r *Router) PostFunc(path string, handler http.HandlerFunc) *Route

PostFunc register the handler in the router, after wrapping it with the middleware

func (*Router) Put Uses

func (r *Router) Put(path string, handler http.Handler) *Route

Put register the handler in the router, after wrapping it with the middleware

func (*Router) PutFunc Uses

func (r *Router) PutFunc(path string, handler http.HandlerFunc) *Route

PutFunc register the handler in the router, after wrapping it with the middleware

func (*Router) RouteFor Uses

func (r *Router) RouteFor(name string, args ...string) template.URL

RouteFor returns a route corresponding to de requested route name. The arguments have the format: RouteFor(name, [key, value]*)

func (*Router) ServeHTTP Uses

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP dispatches the handler that matches with the request

Package router imports 4 packages (graph) and is imported by 3 packages. Updated 2017-01-10. Refresh now. Tools for package owners.