我正在尝试在 Go 中将 Auth0 与 Martini 一起使用。我正在使用他们的示例,但无论我尝试什么,我似乎都无法让它工作。
这是我的代码:
package main
import (
"flag"
"github.com/go-martini/martini"
"github.com/martini-contrib/render"
"github.com/auth0/go-jwt-middleware"
"encoding/base64"
"github.com/dgrijalva/jwt-go"
"net/http"
)
func main() {
m := martini.Classic()
port := flag.String("port", "8000", "HTTP Port")
flag.Parse()
jwtMiddleware := jwtmiddleware.New(jwtmiddleware.Options{
ValidationKeyGetter: func(token *jwt.Token) (interface{}, error) {
decoded, err := base64.URLEncoding.DecodeString("<token>")
if err != nil {
return nil, err
}
return decoded, nil
},
})
m.Use(render.Renderer(render.Options{
IndentJSON: true, // Output human readable JSON
}))
m.Get("/", jwtMiddleware.Handler, func(res http.ResponseWriter, req *http.Request) { // res and req are injected by Martini
res.WriteHeader(200) // HTTP 200
})
// Get the PORT from the environment.
m.RunOnAddr(":" + *port)
}
当我运行它时,我会感到恐慌,说Value not found for type http.Handler
如果我将 更改jwtMiddleware.Handler
为jwtMiddleware.HandlerWithNext
,我会为Value not found for type http.HandlerFunc
.
有谁知道我做错了什么?