router

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Method

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

Method Convert multiple method strings to an slice

func NewStaticHandle

func NewStaticHandle(root string) http.Handler

NewStaticHandle A Handler responds to a Static HTTP request.

func PrepareResponse

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

PrepareResponse Create a response instance from the given value.

func RunRoute

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

RunRoute Return the response for the given rule.

Types

type Closure

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

Closure Anonymous function, Used in Middleware Handler

type Compiled

type Compiled struct {
	Regex string
}

type Middleware

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

MiddlewareFunc Handle an incoming request.

type Pipeline

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

func NewPipeline

func NewPipeline() *Pipeline

Pipeline returns a new Pipeline

func (*Pipeline) Passable

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

Passable set the request being sent through the pipeline.

func (*Pipeline) Pipe

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

Pipe Push a Middleware Handler to the pipeline

func (*Pipeline) Run

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

Run run the pipeline

func (*Pipeline) Through

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

Pipe Batch push Middleware Handlers to the pipeline

type Request

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

type Response

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

Response an HTTP response interface

type Route

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

func New added in v0.3.0

func New() *Route

New Create a new Route instance.

func (*Route) Add

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

Add Add a router

func (*Route) AddRule

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

AddRule Add a Rule to the Router.Rules

func (*Route) Any

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

Any Register a new rule responding to all verbs.

func (*Route) Delete

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

Delete Register a new DELETE rule with the router.

func (*Route) Dispatch

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

Dispatch Dispatch the request

func (*Route) Dump added in v0.3.0

func (r *Route) Dump() []byte

func (*Route) Get

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

Get Register a new GET rule with the router.

func (*Route) Group

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

Group Create a route group

func (*Route) Head

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

Head Register a new Head rule with the router.

func (*Route) Match

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

Match Find the first rule matching a given request.

func (*Route) Middleware

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

Middleware Set the middleware attached to the route.

func (*Route) Options

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

Options Register a new OPTIONS rule with the router.

func (*Route) Patch

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

Patch Register a new PATCH rule with the router.

func (*Route) Post

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

Post Register a new POST rule with the router.

func (*Route) Prefix

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

Prefix Add a prefix to the route URI.

func (*Route) Put

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

Put Register a new PUT rule with the router.

func (*Route) Register

func (r *Route) Register()

Register Register route from the collect.

func (*Route) Static

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

Static Register a new Static rule.

func (*Route) Statics

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

Statics Bulk register Static rule.

type Rule

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

Rule Route rule

func (*Rule) Bind

func (r *Rule) Bind(path string)

Bind Bind the router to a given request for execution.

func (*Rule) GatherRouteMiddleware

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

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

func (*Rule) Matches

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

Matches Determine if the rule matches given request.

func (*Rule) Middleware

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

Middleware Set the middleware attached to the rule.

func (*Rule) Run

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

Run Run the route action and return the response.

Jump to

Keyboard shortcuts

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