router

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 28, 2019 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRouteNameContext

func GetRouteNameContext(ctx context.Context) string

GetRouteNameContext returns route name from context

func SetRouteNameContext

func SetRouteNameContext(ctx context.Context, route string) context.Context

SetRouteNameContext sets name of the route to the context

Types

type Handler

type Handler func(context.Context, []byte) ([]byte, error)

Handler is the callable function

type Middleware

type Middleware func(context.Context, []byte) (context.Context, []byte, error)

Middleware is the called function before the handler every time

type Route

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

Route is contains registered name

type Router

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

Router allows to registers Handlers and call them

func NewRouter

func NewRouter() *Router

NewRouter creates new router

func (*Router) GetAllRoutes

func (r *Router) GetAllRoutes() []*Route

GetAllRoutes allows you get raw list of the routes

func (*Router) GetIDLastRoute

func (r *Router) GetIDLastRoute() uint16

GetIDLastRoute returns id of the last route in routes list

func (*Router) Handle

func (r *Router) Handle(name string, h Handler) int

Handle registers name of the route and returns its ID

func (*Router) HandleWith

func (r *Router) HandleWith(mw Middleware, route string, h Handler) int

HandleWith registers handle with single middleware

func (*Router) Mount

func (r *Router) Mount(prefix string, subRouter *Router)

Mount append routes and middlewares of the subRouter into main router Routes of the subRouter will wrapped middlewares of the main router Prefix can be empty ""

func (*Router) Process

func (r *Router) Process(ctx context.Context, data []byte) ([]byte, error)

Process calls the Handle using the id

func (*Router) ReplaceGetRoutes

func (r *Router) ReplaceGetRoutes(h Handler)

ReplaceGetRoutes allows you to set your own route list view Use GetAllRoutes to get raw list of the routes

func (*Router) Use

func (r *Router) Use(mw Middleware)

Use applies middleware to Handlers added later

func (*Router) UseWithGetRoutes

func (r *Router) UseWithGetRoutes(mw Middleware)

UseWithGetRoutes applies middleware only to Handlers and to _getRoutes If you don't want to apply to the _getRoutes use: just "Use"

Jump to

Keyboard shortcuts

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