1
0
mirror of https://github.com/labstack/echo.git synced 2024-11-28 08:38:39 +02:00

README updated

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2015-03-26 00:42:34 -07:00
parent 1402f61198
commit eb57ae1e39
3 changed files with 34 additions and 26 deletions

View File

@ -3,8 +3,16 @@ Bolt is a fast HTTP router (zero memory allocation) + micro web framework in Go.
### Features
- Zippy router.
- Extensible middleware.
- Hook any middleware / handler.
- Extensible middleware / handler, supports:
- Middleware
- `func(bolt.HandlerFunc) bolt.HandlerFunc`
- `http.HandlerFunc`
- `http.Handler`
- `func(http.Handler) http.Handler`
- Handler
- `func(*bolt.Context)`
- `http.HandlerFunc`
- `http.Handler`
- Serve static files, including index.
### Example
@ -27,11 +35,11 @@ type user struct {
Name string `json:"name"`
}
var users map[string]*user
var users map[string]user
func init() {
users = map[string]*user{
"1": &user{
users = map[string]user{
"1": user{
ID: "1",
Name: "Wreck-It Ralph",
},
@ -41,7 +49,7 @@ func init() {
func createUser(c *bolt.Context) {
u := new(user)
if c.Bind(u) {
users[u.ID] = u
users[u.ID] = *u
c.JSON(http.StatusOK, u)
}
}

32
bolt.go
View File

@ -201,29 +201,15 @@ func (b *Bolt) Run(addr string) {
log.Fatal(http.ListenAndServe(addr, b))
}
// wraps Handler
func (b *Bolt) wrapH(h Handler) HandlerFunc {
switch h := h.(type) {
case func(*Context):
return HandlerFunc(h)
case http.HandlerFunc:
return func(c *Context) {
h.ServeHTTP(c.Response, c.Request)
}
default:
panic("bolt: unknown handler")
}
}
// wraps Middleware
func wrapM(m Middleware) MiddlewareFunc {
switch m := m.(type) {
case func(HandlerFunc) HandlerFunc:
return MiddlewareFunc(m)
case func(http.ResponseWriter, *http.Request):
case http.HandlerFunc, func(http.ResponseWriter, *http.Request), http.Handler:
return func(h HandlerFunc) HandlerFunc {
return func(c *Context) {
m(c.Response, c.Request)
m.(http.Handler).ServeHTTP(c.Response, c.Request)
h(c)
}
}
@ -238,3 +224,17 @@ func wrapM(m Middleware) MiddlewareFunc {
panic("bolt: unknown middleware")
}
}
// wraps Handler
func (b *Bolt) wrapH(h Handler) HandlerFunc {
switch h := h.(type) {
case func(*Context):
return HandlerFunc(h)
case http.HandlerFunc, func(http.ResponseWriter, *http.Request), http.Handler:
return func(c *Context) {
h.(http.Handler).ServeHTTP(c.Response, c.Request)
}
default:
panic("bolt: unknown handler")
}
}

View File

@ -14,11 +14,11 @@ type user struct {
Name string `json:"name"`
}
var users map[string]*user
var users map[string]user
func init() {
users = map[string]*user{
"1": &user{
users = map[string]user{
"1": user{
ID: "1",
Name: "Wreck-It Ralph",
},
@ -28,7 +28,7 @@ func init() {
func createUser(c *bolt.Context) {
u := new(user)
if c.Bind(u) {
users[u.ID] = u
users[u.ID] = *u
c.JSON(http.StatusOK, u)
}
}