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:
parent
1402f61198
commit
eb57ae1e39
20
README.md
20
README.md
@ -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
32
bolt.go
@ -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")
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user