Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/minoritea/air
https://github.com/minoritea/air
Last synced: 1 day ago
JSON representation
- Host: GitHub
- URL: https://github.com/minoritea/air
- Owner: minoritea
- License: bsd-3-clause
- Created: 2016-09-30T14:39:15.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-13T03:29:31.000Z (over 7 years ago)
- Last Synced: 2024-11-12T10:18:29.565Z (2 months ago)
- Language: Go
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# air
`import "github.com/minoritea/air"`* [Overview](#pkg-overview)
* [Index](#pkg-index)## Overview
Package air provides a http router which wraps `github.com/julienschmidt/httprouter`
to support `http.Handler` with URL params via `Context` package.## Index
* [Variables](#pkg-variables)
* [func Compose(h http.Handler, mws ...Middleware) http.Handler](#Compose)
* [func Param(r *http.Request, key string) string](#Param)
* [type H](#H)
* [func (f H) ServeHTTP(w http.ResponseWriter, r *http.Request)](#H.ServeHTTP)
* [type Middleware](#Middleware)
* [func Composer(mws ...Middleware) Middleware](#Composer)
* [type Router](#Router)
* [func New() *Router](#New)
* [func (r *Router) DELETE(path string, h http.Handler)](#Router.DELETE)
* [func (r *Router) GET(path string, h http.Handler)](#Router.GET)
* [func (r *Router) HEAD(path string, h http.Handler)](#Router.HEAD)
* [func (r *Router) Handle(method, path string, h http.Handler)](#Router.Handle)
* [func (r *Router) OPTIONS(path string, h http.Handler)](#Router.OPTIONS)
* [func (r *Router) PATCH(path string, h http.Handler)](#Router.PATCH)
* [func (r *Router) POST(path string, h http.Handler)](#Router.POST)
* [func (r *Router) PUT(path string, h http.Handler)](#Router.PUT)#### Package files
[air.go](/src/github.com/minoritea/air/air.go)## Variables
``` go
var ParamsKey = &contextKey{"key of params"}
```
ParamsKey is the key to get URL params from a Context.## func [Compose](/src/target/air.go?s=2714:2774#L70)
``` go
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](/src/target/air.go?s=2019:2065#L50)
``` go
func Param(r *http.Request, key string) string
```
Param returns the URL parameter from a http.Request object.## type [H](/src/target/air.go?s=3187:3234#L87)
``` go
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](/src/target/air.go?s=3298:3358#L90)
``` go
func (f H) ServeHTTP(w http.ResponseWriter, r *http.Request)
```
ServeHTTP is required to implement http.Handler interface.## type [Middleware](/src/target/air.go?s=2530:2577#L66)
``` go
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](/src/target/air.go?s=2967:3010#L79)
``` go
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](/src/target/air.go?s=450:490#L8)
``` go
type Router struct{ *httprouter.Router }
```
Router is a simple URL router which acts as a http.Handler.### func [New](/src/target/air.go?s=521:539#L11)
``` go
func New() *Router
```
New returns a new Router.### func (\*Router) [DELETE](/src/target/air.go?s=1052:1104#L29)
``` go
func (r *Router) DELETE(path string, h http.Handler)
```
DELETE is a shortcut for Handle with "DELETE" method.### func (\*Router) [GET](/src/target/air.go?s=1189:1238#L32)
``` go
func (r *Router) GET(path string, h http.Handler)
```
GET is a shortcut for Handle with "GET" method.### func (\*Router) [HEAD](/src/target/air.go?s=1322:1372#L35)
``` go
func (r *Router) HEAD(path string, h http.Handler)
```
HEAD is a shortcut for Handle with "HEAD" method.### func (\*Router) [Handle](/src/target/air.go?s=866:926#L23)
``` go
func (r *Router) Handle(method, path string, h http.Handler)
```
Handle registers a new http.Handler to the Router.### func (\*Router) [OPTIONS](/src/target/air.go?s=1463:1516#L38)
``` go
func (r *Router) OPTIONS(path string, h http.Handler)
```
OPTIONS is a shortcut for Handle with "OPTIONS" method.### func (\*Router) [PATCH](/src/target/air.go?s=1606:1657#L41)
``` go
func (r *Router) PATCH(path string, h http.Handler)
```
PATCH is a shortcut for Handle with "PATCH" method.### func (\*Router) [POST](/src/target/air.go?s=1743:1793#L44)
``` go
func (r *Router) POST(path string, h http.Handler)
```
POST is a shortcut for Handle with "POST" method.### func (\*Router) [PUT](/src/target/air.go?s=1876:1925#L47)
``` go
func (r *Router) PUT(path string, h http.Handler)
```
PUT is a shortcut for Handle with "PUT" method.- - -
Generated by [godoc2md](http://godoc.org/github.com/davecheney/godoc2md)