简体   繁体   中英

go jwt ValidationKeyGetter does not compile

I am new to go. I am trying to set up a secure webserver using go and jwt, but I cannot get this to compile:

mw := jwtmiddleware.New(jwtmiddleware.Options{
        ValidationKeyGetter: func (token *jwt.Token) (interface{}, error) {
            return mySigningKey, nil
        },
        SigningMethod: jwt.SigningMethodHS256,
    })

but I only get the following error (from the compiler and the analyzer):

cannot use func literal (type func(*"webserver/vendor/github.com/dgrijalva/jwt-go".Token) (interface {}, error)) as type "github.com/dgrijalva/jwt-go".Keyfunc in field value   

I have tried making it a separate named func but that didn't help. The jwt library shows

type Keyfunc func(*Token) (interface{}, error)

so, it should match the signature. The code is the same in several online examples including auth0.com .

I have had success running simpler go programs, including serving a simple web page, so the compiler is working correctly.

Running on ubuntu 18.04 with the newest stable version of go and packages (downloaded and installed a few days ago). Thanks

It seems the package was not in vendor/github.com. I did the following:

cp -R ../github.com/auth0 vendor/github.com/auth0

and it now compiles.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM