router

package
v0.0.0-...-4a0794a Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2017 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BadPathPattern  = fmt.Errorf("Bad path pattern")
	NotEnoughParams = fmt.Errorf("Not enough params to substitute")
	TooManyparams   = fmt.Errorf("Too many params to substitute")
)

Functions

func ParamsFromContext

func ParamsFromContext(ctx context.Context) denco.Params

ParamsFromContext extract path params.

Types

type FallbackRouter

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

FallbackRouter is used to regist fallback handlers.

func NewFallbackRouter

func NewFallbackRouter() *FallbackRouter

NewFallbackRouter creates a FallbackRouter.

func (*FallbackRouter) Configure

func (r *FallbackRouter) Configure() error

Configure construct router.

func (*FallbackRouter) Handler

func (r *FallbackRouter) Handler(path string, handler jimu.FallbackHandler)

Handler add a FallbackHandler to the router.

func (*FallbackRouter) Serve

func (r *FallbackRouter) Serve(w http.ResponseWriter, req *http.Request, msg string, status int)

Serve implement FallbackHandler.

type Option

type Option func(*Router) error

Option for configuring Router.

func FallbackHandler

func FallbackHandler(fallbackHandler jimu.FallbackHandler) Option

FallbackHandler set the fallback handler (for 404 ...) for the router.

type Path

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

func MustPath

func MustPath(path string) *Path

MustPath creates a path or panic if there is error.

func NewPath

func NewPath(path string) (*Path, error)

NewPath creates a Path.

func (*Path) Build

func (p *Path) Build(params ...interface{}) (string, error)

Build concrete path from params. Param can be string, denco.Param or any fmt.Sprint-able object.

func (*Path) BuildURL

func (p *Path) BuildURL(baseURL *url.URL, params ...interface{}) (string, error)

Build a full url.

func (*Path) String

func (p *Path) String() string

String implement Stringer interface. Return the path pattern.

type Router

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

Router is a wrapper around denco's router.

func New

func New() *Router

New creates a Router.

func (*Router) Configure

func (r *Router) Configure() error

Configure process options and construct router.

func (*Router) Handler

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

Handler add an http handler to the router.

func (*Router) HandlerFunc

func (r *Router) HandlerFunc(path string, handlerFunc http.HandlerFunc, methods ...string)

HandlerFunc add an http handler func to the router.

func (*Router) Options

func (r *Router) Options(options ...Option)

Options add options for the router.

func (*Router) ServeHTTP

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

ServeHTTP implement http.Handler.

Jump to

Keyboard shortcuts

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