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:
+4
-4
@@ -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)
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user