go - 我在 golang 中的令牌验证功能中出现错误
问题描述
我的代码:
func ValidateToken(w http.ResponseWriter, r *http.Request) {
token, err := request.ParseFromRequestWithClaims(r, request.OAuth2Extractor, &models.Claim{}, func(token *jwt.Token) (interface{}, error) {
return publicKey, nil
})
if err != nil {
fmt.Fprintln(w, "Invalid Token")
return
}
if token.Valid {
w.WriteHeader(http.StatusAccepted)
fmt.Fprintln(w, "welcome to the system")
} else {
w.WriteHeader(http.StatusUnauthorized)
fmt.Fprintln(w, "your token is not valid")
}
}
我有问题:
cannot use func literal (type func(*"github.com/tokens/vendor/github.com/dgrijalva/jwt-go".Token) (interface {}, error)) as type "github.com/dgrijalva/jwt-go".Keyfunc in argument to request.ParseFromRequestWithClaims
解决方案
推荐阅读
- java - 使用 Livy 提交 Spark 作业时出错:用户没有初始化 Spark 上下文
- python - 使用python中的字典计算两点之间的距离
- c# - EFCore 2 Fluent API 构建自定义映射规则
- python - AWS Python lambda 在第一次超时后永远超时
- excel - 如何使用命令按钮保存工作簿和清除用户窗体?
- postgresql - 在覆盆子上直接远程连接到 postgresql 12
- python - Python使用“父”键从平面字典中创建嵌套结构
- reactjs - 如何在另一个组件中获取 Ant Design Form 数据
- asp.net - 将值 JSON 转换为类型实体 asp.net 时出错
- python - Python,读取文本文件并打印出无效用户名列表