air

package module
v0.0.0-...-2f05fcb Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2017 License: BSD-3-Clause Imports: 3 Imported by: 0

README

air

import "github.com/minoritea/air"

Overview

Package air provides a http router which wraps github.com/julienschmidt/httprouter to support http.Handler with URL params via Context package.

Index

Package files

air.go

Variables

var ParamsKey = &contextKey{"key of params"}

ParamsKey is the key to get URL params from a Context.

func Compose

func Compose(h http.Handler, mws ...Middleware) http.Handler

Compose assembles middlewares into a http.Handler. Note that middlewares are applied from right to left, then handler is called.

func Param

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

Param returns the URL parameter from a http.Request object.

type H

type H func(http.ResponseWriter, *http.Request)

H is a copy of http.HandlerFunc. It makes easy to cast handler functions to http.Handler.

func (H) ServeHTTP
func (f H) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP is required to implement http.Handler interface.

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware is an alias of func(http.Handler) http.Handler. These functions wrap a http.Handler with some additonal features.

func middleware(next http.Handler) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        // some additional features...
        next(w, r)
    })
}
func Composer
func Composer(mws ...Middleware) Middleware

Composer returns a new middleware which is composed of passed middlewares. It is just a partially applied function of Compose .

type Router

type Router struct{ *httprouter.Router }

Router is a simple URL router which acts as a http.Handler.

func New
func New() *Router

New returns a new Router.

func (*Router) DELETE
func (r *Router) DELETE(path string, h http.Handler)

DELETE is a shortcut for Handle with "DELETE" method.

func (*Router) GET
func (r *Router) GET(path string, h http.Handler)

GET is a shortcut for Handle with "GET" method.

func (*Router) HEAD
func (r *Router) HEAD(path string, h http.Handler)

HEAD is a shortcut for Handle with "HEAD" method.

func (*Router) Handle
func (r *Router) Handle(method, path string, h http.Handler)

Handle registers a new http.Handler to the Router.

func (*Router) OPTIONS
func (r *Router) OPTIONS(path string, h http.Handler)

OPTIONS is a shortcut for Handle with "OPTIONS" method.

func (*Router) PATCH
func (r *Router) PATCH(path string, h http.Handler)

PATCH is a shortcut for Handle with "PATCH" method.

func (*Router) POST
func (r *Router) POST(path string, h http.Handler)

POST is a shortcut for Handle with "POST" method.

func (*Router) PUT
func (r *Router) PUT(path string, h http.Handler)

PUT is a shortcut for Handle with "PUT" method.


Generated by godoc2md

Documentation

Overview

Package air provides a http router which wraps `github.com/julienschmidt/httprouter` to support `http.Handler` with URL params via `Context` package.

Index

Constants

This section is empty.

Variables

View Source
var ParamsKey = &contextKey{"key of params"}

ParamsKey is the key to get URL params from a Context.

Functions

func Compose

func Compose(h http.Handler, mws ...Middleware) http.Handler

Compose assembles middlewares into a http.Handler. Note that middlewares are applied from right to left, then handler is called.

func Param

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

Param returns the URL parameter from a http.Request object.

Types

type H

type H func(http.ResponseWriter, *http.Request)

H is a copy of http.HandlerFunc. It makes easy to cast handler functions to http.Handler.

func (H) ServeHTTP

func (f H) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP is required to implement http.Handler interface.

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware is an alias of `func(http.Handler) http.Handler`. These functions wrap a http.Handler with some additonal features.

func middleware(next http.Handler) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        // some additional features...
        next(w, r)
    })
}

func Composer

func Composer(mws ...Middleware) Middleware

Composer returns a new middleware which is composed of passed middlewares. It is just a partially applied function of `Compose` .

type Router

type Router struct{ *httprouter.Router }

Router is a simple URL router which acts as a http.Handler.

func New

func New() *Router

New returns a new Router.

func (*Router) DELETE

func (r *Router) DELETE(path string, h http.Handler)

DELETE is a shortcut for Handle with "DELETE" method.

func (*Router) GET

func (r *Router) GET(path string, h http.Handler)

GET is a shortcut for Handle with "GET" method.

func (*Router) HEAD

func (r *Router) HEAD(path string, h http.Handler)

HEAD is a shortcut for Handle with "HEAD" method.

func (*Router) Handle

func (r *Router) Handle(method, path string, h http.Handler)

Handle registers a new http.Handler to the Router.

func (*Router) OPTIONS

func (r *Router) OPTIONS(path string, h http.Handler)

OPTIONS is a shortcut for Handle with "OPTIONS" method.

func (*Router) PATCH

func (r *Router) PATCH(path string, h http.Handler)

PATCH is a shortcut for Handle with "PATCH" method.

func (*Router) POST

func (r *Router) POST(path string, h http.Handler)

POST is a shortcut for Handle with "POST" method.

func (*Router) PUT

func (r *Router) PUT(path string, h http.Handler)

PUT is a shortcut for Handle with "PUT" method.

Jump to

Keyboard shortcuts

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