router

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2019 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(w http.ResponseWriter, r *http.Request, params Params)

Handle is a function that can be registered to a route to handle HTTP requests.

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) NotFound

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

NotFound sets a NotFound handle.

func (*Router) Panic added in v0.7.1

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

Panic sets a panic handle.

func (*Router) ServeHTTP

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

ServeHTTP implements the http.Handler interface.

func (*Router) Validates added in v0.7.1

func (router *Router) Validates(validates Validates)

Validates sets param validates.

type Validate

type Validate func(s string) (ok bool)

Validate is a function to validate route params

type Validates added in v0.7.1

type Validates map[string]Validate

Validates is a validate map to validate router params.

Jump to

Keyboard shortcuts

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