mirror of
https://github.com/labstack/echo.git
synced 2026-05-16 09:48:24 +02:00
@@ -8,7 +8,7 @@ Bolt is a fast HTTP router (zero memory allocation) + micro web framework in Go.
|
|||||||
|
|
||||||
### Benchmark
|
### Benchmark
|
||||||
Based on [julienschmidt/go-http-routing-benchmark] (https://github.com/vishr/go-http-routing-benchmark)
|
Based on [julienschmidt/go-http-routing-benchmark] (https://github.com/vishr/go-http-routing-benchmark)
|
||||||
#### [GitHub](http://developer.github.com/v3)
|
##### [GitHub API](http://developer.github.com/v3)
|
||||||
```
|
```
|
||||||
BenchmarkAce_GithubAll 20000 70743 ns/op 13792 B/op 167 allocs/op
|
BenchmarkAce_GithubAll 20000 70743 ns/op 13792 B/op 167 allocs/op
|
||||||
BenchmarkBear_GithubAll 10000 251638 ns/op 79952 B/op 943 allocs/op
|
BenchmarkBear_GithubAll 10000 251638 ns/op 79952 B/op 943 allocs/op
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ func (c *Context) JSON(n int, i interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) File(n int, file, name string) {
|
func (c *Context) File(n int, file, name string) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next executes the next handler in the chain.
|
// Next executes the next handler in the chain.
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/labstack/bolt"
|
"github.com/labstack/bolt"
|
||||||
|
mw "github.com/labstack/bolt/middleware"
|
||||||
)
|
)
|
||||||
|
|
||||||
type user struct {
|
type user struct {
|
||||||
@@ -40,6 +41,7 @@ func getUser(c *bolt.Context) {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
b := bolt.New()
|
b := bolt.New()
|
||||||
|
b.Use(mw.Logger())
|
||||||
b.Index("public/index.html")
|
b.Index("public/index.html")
|
||||||
b.Static("/js", "public/js")
|
b.Static("/js", "public/js")
|
||||||
b.Post("/users", createUser)
|
b.Post("/users", createUser)
|
||||||
|
|||||||
@@ -13,20 +13,20 @@ func Logger() bolt.HandlerFunc {
|
|||||||
start := time.Now()
|
start := time.Now()
|
||||||
c.Next()
|
c.Next()
|
||||||
end := time.Now()
|
end := time.Now()
|
||||||
co := color.Green
|
col := color.Green
|
||||||
m := c.Request.Method
|
m := c.Request.Method
|
||||||
p := c.Request.URL.Path
|
p := c.Request.URL.Path
|
||||||
s := c.Response.Status()
|
s := c.Response.Status()
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case s >= 500:
|
case s >= 500:
|
||||||
co = color.Red
|
col = color.Red
|
||||||
case s >= 400:
|
case s >= 400:
|
||||||
co = color.Yellow
|
col = color.Yellow
|
||||||
case s >= 300:
|
case s >= 300:
|
||||||
co = color.Cyan
|
col = color.Cyan
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("%s %s %s %s", m, p, co(s), end.Sub(start))
|
log.Printf("%s %s %s %s", m, p, col(s), end.Sub(start))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user