router

package
v0.15.6 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handle

type Handle func(http.ResponseWriter, *http.Request, Params)

Handle is a function that can be registered to a route to handle HTTP requests. Like http.HandlerFunc, but has a third parameter for the values of wildcards (path variables).

type Param added in v0.7.2

type Param struct {
	Key   string
	Value string
}

Param is a single URL parameter, consisting of a key and a value.

type Params added in v0.7.1

type Params []Param

Params is a Param-slice, as returned by the router. The slice is ordered, the first URL parameter is also the first slice value. It is therefore safe to read values by the index.

func (Params) ByName added in v0.7.2

func (ps Params) ByName(name string) string

ByName returns the value of the first Param which key matches the given name. If no matching Param is found, an empty string is returned.

type Router

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

Router is a http.Handler which can be used to dispatch requests to different handler functions.

func New

func New() *Router

New returns a new initialized Router.

func (*Router) Handle

func (router *Router) Handle(method string, path string, handle Handle)

Handle registers a new request handle with the given path and method.

func (*Router) HandleOptions added in v0.7.6

func (router *Router) HandleOptions(handle func(http.ResponseWriter, *http.Request))

HandleOptions sets a options handle.

func (*Router) HandlePanic added in v0.7.6

func (router *Router) HandlePanic(handle func(http.ResponseWriter, *http.Request, interface{}))

HandlePanic sets a panic handle.

func (*Router) NotFound

func (router *Router) NotFound(handle http.HandlerFunc)

NotFound sets a NotFound handle.

func (*Router) ServeHTTP

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

ServeHTTP implements the http.Handler interface.

func (*Router) SetValidateFn added in v0.9.1

func (router *Router) SetValidateFn(name string, fn ValidateFn)

SetValidateFn sets param validate function.

type ValidateFn added in v0.9.1

type ValidateFn func(s string) (ok bool)

ValidateFn is a function to validate route params

Jump to

Keyboard shortcuts

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