router

package module
v0.0.0-...-3d43859 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2016 License: MIT Imports: 4 Imported by: 0

README

router

A middleware that works well (but not exclusively) with rkusa/web and provides high performance HTTP request routing using httptreemux.

Build Status GoDoc

Example
routes := router.New()

routes.GET("/users/:id", func(rw http.ResponseWriter, r *http.Request) {
  id := router.Param(r, "id")
  // ...
})

app.Use(routes.Middleware())

License

MIT

Documentation

Overview

Package router is a middleware that works well (but not exclusively) with rkusa/web(https://github.com/rkusa/web) and provides high performance HTTP request routing using httptreemux(http://github.com/dimfeld/httptreemux).

routes := router.New()

routes.GET("/users/:id", func(rw http.ResponseWriter, r *http.Request) {
  id := router.Param(r, "id")
  // ...
})

app.Use(routes.Middleware())

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Param

func Param(r *http.Request, name string) string

Param reads the parameter for the given name from the provided request. The result will be an empty string, if the parameter does not exist.

func ParamFromContext

func ParamFromContext(ctx context.Context, name string) string

Param reads the parameter for the given name from the provided context. The result will be an empty string, if the parameter does not exist.

Types

type Router

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

Router can be used to dispatch requests to different handler functions via configurable routes

func New

func New() *Router

New returns a new initialized Router.

func (*Router) DELETE

func (rt *Router) DELETE(path string, handler http.HandlerFunc)

DELETE is a shortcut for router.Handle("DELETE", path, handle)

func (*Router) GET

func (rt *Router) GET(path string, handler http.HandlerFunc)

GET is a shortcut for router.Handle("GET", path, handle)

func (*Router) Group

func (rt *Router) Group(path string) *Router

Group creates a new route group with the given path prefix. All route created using the returned Router are prefixed accoringly.

func (*Router) HEAD

func (rt *Router) HEAD(path string, handler http.HandlerFunc)

HEAD is a shortcut for router.Handle("HEAD", path, handle)

func (*Router) Handle

func (rt *Router) Handle(method, path string, handler http.HandlerFunc)

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

func (*Router) Middleware

func (rt *Router) Middleware() func(http.ResponseWriter, *http.Request, http.HandlerFunc)

Middleware returns a middleware that serves all registered routes.

func (*Router) OPTIONS

func (rt *Router) OPTIONS(path string, handler http.HandlerFunc)

OPTIONS is a shortcut for router.Handle("OPTIONS", path, handle)

func (*Router) PATCH

func (rt *Router) PATCH(path string, handler http.HandlerFunc)

PATCH is a shortcut for router.Handle("PATCH", path, handle)

func (*Router) POST

func (rt *Router) POST(path string, handler http.HandlerFunc)

POST is a shortcut for router.Handle("POST", path, handle)

func (*Router) PUT

func (rt *Router) PUT(path string, handler http.HandlerFunc)

PUT is a shortcut for router.Handle("PUT", path, handle)

Jump to

Keyboard shortcuts

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