去jwt ValidationKeyGetter不编译

时间:2018-10-07 06:08:09

标签: go jwt

我是新手。我正在尝试使用go和jwt设置安全的Web服务器,但是无法编译该文件:

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

但是我只收到以下错误(来自编译器和分析器):

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   

我尝试将其单独命名为func,但这没有帮助。 jwt库显示

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

因此,它应该与签名匹配。在包括auth0.com在内的几个在线示例中,代码是相同的。

我已经成功运行了更简单的go程序,包括为一个简单的网页提供服务,因此编译器可以正常工作。

在ubuntu 18.04上运行,带有最新的go和package稳定版本(几天前已下载并安装)。谢谢

1 个答案:

答案 0 :(得分:0)

似乎该软件包不在vendor / github.com中。我做了以下事情:

   RewriteEngine On
    RewriteBase /
RewriteCond %{REQUEST_URI} ^/feed/fullnews/
RewriteCond %{HTTP_USER_AGENT} !FeedBurner
RewriteRule (.*)  http://feeds.feedburner.com/XTfullnews [R=301,L]

RewriteCond %{REQUEST_URI} ^/feed/fullguide/
RewriteCond %{HTTP_USER_AGENT} !FeedBurner
RewriteRule (.*)  http://feeds.feedburner.com/XTfullguide [R=301,L]

RewriteCond %{REQUEST_URI} ^/feed/recensioni/
RewriteCond %{HTTP_USER_AGENT} !FeedBurner
RewriteRule (.*)  http://feeds.feedburner.com/XiaomitodayRecensioni [R=301,L]

RewriteCond %{HTTP_HOST} www\.xiaomitoday\.it$ [NC]
RewriteCond %{REQUEST_URI} ^/category/notizie/feed/
RewriteCond %{HTTP_USER_AGENT} !FeedBurner
RewriteRule (.*)  http://feeds.feedburner.com/XiaomitodayNews [R=301,L]

RewriteCond %{REQUEST_URI} ^/category/guide/feed/
RewriteCond %{HTTP_USER_AGENT} !FeedBurner
RewriteRule (.*)  http://feeds.feedburner.com/XiaomitodayGuide [R=301,L]  

RewriteCond %{REQUEST_URI} ^/category/recensione/feed/
RewriteCond %{HTTP_USER_AGENT} !FeedBurner
RewriteRule (.*)  http://feeds.feedburner.com/XiaomitodayRecensioni [R=301,L]

RewriteCond %{REQUEST_URI} ^/category/offerte-sconti-coupon/feed
RewriteCond %{HTTP_USER_AGENT} !FeedBurner
RewriteRule (.*)  http://feeds.feedburner.com/XiaomitodayOfferte [R=301,L] 

RewriteCond %{REQUEST_URI} ^/feed/?$
RewriteCond %{HTTP_USER_AGENT} !FeedBurner
RewriteRule (.*)  http://feeds.feedburner.com/XTguidenewsreview [R=301,L] 

RewriteCond %{REQUEST_URI} ^/feed/offerte_smartphone/?$
RewriteCond %{HTTP_USER_AGENT} !FeedBurner
RewriteRule (.*)  http://feeds.feedburner.com/XTofferteSmartphone [R=301,L] 

RewriteCond %{REQUEST_URI} ^/feed/offerte_tablet/?$
RewriteCond %{HTTP_USER_AGENT} !FeedBurner
RewriteRule (.*)  http://feeds.feedburner.com/XTofferteTablet [R=301,L]

RewriteCond %{REQUEST_URI} ^/feed/offerte_wearable/?$
RewriteCond %{HTTP_USER_AGENT} !FeedBurner
RewriteRule (.*)  http://feeds.feedburner.com/XTofferteWearable [R=301,L]

RewriteCond %{REQUEST_URI} ^/feed/offerte_cam/?$
RewriteCond %{HTTP_USER_AGENT} !FeedBurner
RewriteRule (.*)  http://feeds.feedburner.com/XTofferteCam [R=301,L] 

RewriteCond %{REQUEST_URI} ^/feed/offerte_droni/?$
RewriteCond %{HTTP_USER_AGENT} !FeedBurner
RewriteRule (.*)  http://feeds.feedburner.com/XTofferteDroni [R=301,L] 

RewriteCond %{REQUEST_URI} ^/feed/offerte_tvbox/?$
RewriteCond %{HTTP_USER_AGENT} !FeedBurner
RewriteRule (.*)  http://feeds.feedburner.com/XTofferteTvbox [R=301,L] 

RewriteCond %{REQUEST_URI} ^/feed/offerte_casa/?$
RewriteCond %{HTTP_USER_AGENT} !FeedBurner
RewriteRule (.*)  http://feeds.feedburner.com/XTofferteSmartHome [R=301,L] 

RewriteCond %{REQUEST_URI} ^/feed/offerte_altro/?$
RewriteCond %{HTTP_USER_AGENT} !FeedBurner
RewriteRule (.*)  http://feeds.feedburner.com/XTofferteAltro [R=301,L] 

#RewriteCond %{HTTP_USER_AGENT} !FeedBurner
#RewriteRule feed - [R=403]

它现在可以编译。