thinkgo: github.com/thinkoner/thinkgo/router Index | Files

package router

import "github.com/thinkoner/thinkgo/router"

Index

Package Files

metch.go middleware.go pipeline.go resource_controller.go route.go router.go rule.go static.go utils.go

func Method Uses

func Method(method ...string) []string

Method Convert multiple method strings to an slice

func NewStaticHandle Uses

func NewStaticHandle(root string) http.Handler

NewStaticHandle A Handler responds to a Static HTTP request.

func PrepareResponse Uses

func PrepareResponse(request *context.Request, rule *Rule, result interface{}) interface{}

PrepareResponse Create a response instance from the given value.

func RunRoute Uses

func RunRoute(request *context.Request, rule *Rule) interface{}

RunRoute Return the response for the given rule.

type Closure Uses

type Closure func(req *context.Request) interface {
}

Closure Anonymous function, Used in Middleware Handler

type Compiled Uses

type Compiled struct {
    Regex string
}

type Middleware Uses

type Middleware func(request *context.Request, next Closure) interface{}

MiddlewareFunc Handle an incoming request.

type Pipeline Uses

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

func NewPipeline Uses

func NewPipeline() *Pipeline

Pipeline returns a new Pipeline

func (*Pipeline) Passable Uses

func (p *Pipeline) Passable(passable *context.Request) *Pipeline

Passable set the request being sent through the pipeline.

func (*Pipeline) Pipe Uses

func (p *Pipeline) Pipe(m Middleware) *Pipeline

Pipe Push a Middleware Handler to the pipeline

func (*Pipeline) Run Uses

func (p *Pipeline) Run(destination Middleware) interface{}

Run run the pipeline

func (*Pipeline) Through Uses

func (p *Pipeline) Through(hls []Middleware) *Pipeline

Pipe Batch push Middleware Handlers to the pipeline

type Request Uses

type Request interface {
    GetMethod() string
    GetPath() string
}

type Response Uses

type Response interface {
    Send(w http.ResponseWriter)
}

Response an HTTP response interface

type Route Uses

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

func NewRoute Uses

func NewRoute() *Route

NewRoute Create a new Route instance.

func (*Route) Add Uses

func (r *Route) Add(method []string, pattern string, handler interface{}) *Route

Add Add a router

func (*Route) AddRule Uses

func (r *Route) AddRule(rule *Rule) *Rule

AddRule Add a Rule to the Router.Rules

func (*Route) Any Uses

func (r *Route) Any(pattern string, handler interface{}) *Route

Any Register a new rule responding to all verbs.

func (*Route) Delete Uses

func (r *Route) Delete(pattern string, handler interface{}) *Route

Delete Register a new DELETE rule with the router.

func (*Route) Dispatch Uses

func (r *Route) Dispatch(request Request) (*Rule, error)

Dispatch Dispatch the request

func (*Route) Get Uses

func (r *Route) Get(pattern string, handler interface{}) *Route

Get Register a new GET rule with the router.

func (*Route) Group Uses

func (r *Route) Group(callback func(group *Route)) *Route

Group Create a route group

func (*Route) Head Uses

func (r *Route) Head(pattern string, handler interface{}) *Route

Head Register a new Head rule with the router.

func (*Route) Match Uses

func (r *Route) Match(request Request) (*Rule, error)

Match Find the first rule matching a given request.

func (*Route) Middleware Uses

func (r *Route) Middleware(middlewares ...Middleware) *Route

Middleware Set the middleware attached to the route.

func (*Route) Options Uses

func (r *Route) Options(pattern string, handler interface{}) *Route

Options Register a new OPTIONS rule with the router.

func (*Route) Patch Uses

func (r *Route) Patch(pattern string, handler interface{}) *Route

Patch Register a new PATCH rule with the router.

func (*Route) Post Uses

func (r *Route) Post(pattern string, handler interface{}) *Route

Post Register a new POST rule with the router.

func (*Route) Prefix Uses

func (r *Route) Prefix(prefix string) *Route

Prefix Add a prefix to the route URI.

func (*Route) Put Uses

func (r *Route) Put(pattern string, handler interface{}) *Route

Put Register a new PUT rule with the router.

func (*Route) Register Uses

func (r *Route) Register()

Register Register route from the collect.

func (*Route) Static Uses

func (r *Route) Static(path, root string)

Static Register a new Static rule.

func (*Route) Statics Uses

func (r *Route) Statics(statics map[string]string)

Statics Bulk register Static rule.

type Rule Uses

type Rule struct {
    Compiled *Compiled
    // contains filtered or unexported fields
}

Rule Route rule

func (*Rule) Bind Uses

func (r *Rule) Bind(path string)

Bind Bind the router to a given request for execution.

func (*Rule) GatherRouteMiddleware Uses

func (r *Rule) GatherRouteMiddleware() []Middleware

GatherRouteMiddleware Get all middleware, including the ones from the controller.

func (*Rule) Matches Uses

func (r *Rule) Matches(method, path string) bool

Matches Determine if the rule matches given request.

func (*Rule) Middleware Uses

func (r *Rule) Middleware(middlewares ...Middleware) *Rule

Middleware Set the middleware attached to the rule.

func (*Rule) Run Uses

func (r *Rule) Run(request *context.Request) interface{}

Run Run the route action and return the response.

Package router imports 11 packages (graph) and is imported by 2 packages. Updated 2019-01-21. Refresh now. Tools for package owners.