1
0
mirror of https://github.com/labstack/echo.git synced 2025-10-30 23:57:38 +02:00

Middleware example

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2015-03-12 20:50:33 -07:00
parent 3b3137b31e
commit 40330ae7c0
4 changed files with 8 additions and 7 deletions

View File

@@ -13,20 +13,20 @@ func Logger() bolt.HandlerFunc {
start := time.Now()
c.Next()
end := time.Now()
co := color.Green
col := color.Green
m := c.Request.Method
p := c.Request.URL.Path
s := c.Response.Status()
switch {
case s >= 500:
co = color.Red
col = color.Red
case s >= 400:
co = color.Yellow
col = color.Yellow
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))
}
}