1
0
mirror of https://github.com/labstack/echo.git synced 2026-05-16 09:48:24 +02:00

Flexible handler and middleware

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2015-03-25 08:50:24 -07:00
parent 99124cda0a
commit e49e74aeac
8 changed files with 138 additions and 86 deletions
+4 -4
View File
@@ -10,10 +10,10 @@ import (
)
type (
BasicAuthFunc func(usr, pwd string) bool
BasicAuthFunc func(string, string) bool
AuthorizedHandler bolt.HandlerFunc
UnauthorizedHandler func(c *bolt.Context, err error)
JwtKeyFunc func(kid string) ([]byte, error)
UnauthorizedHandler func(*bolt.Context, error)
JwtKeyFunc func(string) ([]byte, error)
Claims map[string]interface{}
)
@@ -57,7 +57,7 @@ func JwtAuth(ah AuthorizedHandler, uah UnauthorizedHandler, fn JwtKeyFunc) bolt.
if t.Valid {
c.Set("claims", Claims(t.Claims))
ah(c)
c.Next()
// c.Next()
} else {
// TODO: capture errors
uah(c, err)
+4 -4
View File
@@ -8,10 +8,10 @@ import (
"github.com/labstack/gommon/color"
)
func Logger() bolt.HandlerFunc {
return func(c *bolt.Context) {
func Logger(h bolt.HandlerFunc) bolt.HandlerFunc {
return bolt.HandlerFunc(func(c *bolt.Context) {
start := time.Now()
c.Next()
h(c)
end := time.Now()
col := color.Green
m := c.Request.Method
@@ -28,5 +28,5 @@ func Logger() bolt.HandlerFunc {
}
log.Printf("%s %s %s %s", m, p, col(s), end.Sub(start))
}
})
}