在Linux Mint上使用Go获取OAuth2时出现奇怪的错误。

huangapple go评论84阅读模式
英文:

Go Get OAuth2 Giving Me Weird Errors on Linux Mint

问题

尝试按照https://jacobmartins.com/2016/02/29/getting-started-with-oauth2-in-go/的步骤进行操作。

当我运行go get golang.org/x/oauth2时,没有出现任何奇怪的情况,但是当我尝试使用go run main.go运行代码时,在我的终端中出现以下错误信息:

# google.golang.org/grpc/credentials
../../../google.golang.org/grpc/credentials/credentials_util_pre_go17.go:58:32: 错误:对未定义的字段或方法‘GetCertificate’的引用
   GetCertificate:           cfg.GetCertificate,
                                ^
../../../google.golang.org/grpc/credentials/credentials_util_pre_go17.go:69:32: 错误:对未定义的字段或方法‘ClientSessionCache’的引用
   ClientSessionCache:       cfg.ClientSessionCache,
                                ^
../../../google.golang.org/grpc/credentials/credentials_util_pre_go17.go:72:32: 错误:对未定义的字段或方法‘CurvePreferences’的引用
   CurvePreferences:         cfg.CurvePreferences,
                                ^
../../../google.golang.org/grpc/credentials/credentials_util_pre_go17.go:58:3: 错误:在‘tls.Config’中未知的字段‘GetCertificate’
   GetCertificate:           cfg.GetCertificate,
   ^
# golang.org/x/net/http2/hpack
../../../golang.org/x/net/http2/hpack/huffman.go:14:20: 错误:对未定义的标识符‘sync.Pool’的引用
 var bufPool = sync.Pool{
                    ^
../../../golang.org/x/net/http2/hpack/huffman.go:14:24: 错误:在顶层声明后缺少‘;’或换行符
 var bufPool = sync.Pool{
                        ^
# golang.org/x/net/context/ctxhttp
../../../golang.org/x/net/context/ctxhttp/ctxhttp_pre17.go:36:5: 错误:对未定义的字段或方法‘Cancel’的引用
  req.Cancel = cancel
     ^
# golang.org/x/oauth2/jws
../../../golang.org/x/oauth2/jws/jws.go:75:17: 错误:对未定义的标识符‘base64.RawURLEncoding’的引用
   return base64.RawURLEncoding.EncodeToString(b), nil
                 ^
../../../golang.org/x/oauth2/jws/jws.go:93:16: 错误:对未定义的标识符‘base64.RawURLEncoding’的引用
  return base64.RawURLEncoding.EncodeToString(b), nil
                ^
../../../golang.org/x/oauth2/jws/jws.go:113:16: 错误:对未定义的标识符‘base64.RawURLEncoding’的引用
  return base64.RawURLEncoding.EncodeToString(b), nil
                ^
../../../golang.org/x/oauth2/jws/jws.go:124:25: 错误:对未定义的标识符‘base64.RawURLEncoding’的引用
  decoded, err := base64.RawURLEncoding.DecodeString(s[1])
                         ^
../../../golang.org/x/oauth2/jws/jws.go:151:41: 错误:对未定义的标识符‘base64.RawURLEncoding’的引用
  return fmt.Sprintf("%s.%s", ss, base64.RawURLEncoding.EncodeToString(sig)), nil
                                         ^
../../../golang.org/x/oauth2/jws/jws.go:174:33: 错误:对未定义的标识符‘base64.RawURLEncoding’的引用
  signatureString, err := base64.RawURLEncoding.DecodeString(parts[2])

Go版本是go version xgcc (Ubuntu 4.9.3-0ubuntu4) 4.9.3 linux/amd64

运行的是Linux Mint 17.3 Cinnamon

有人知道我做错了什么吗?

英文:

Attempting to follow along with https://jacobmartins.com/2016/02/29/getting-started-with-oauth2-in-go/

When I run go get golang.org/x/oauth2 nothing weird comes up, but when attempting to run the code using go run main.go

I get the following in my terminal:

# google.golang.org/grpc/credentials
../../../google.golang.org/grpc/credentials/credentials_util_pre_go17.go:58:32: error: reference to undefined field or method ‘GetCertificate’
   GetCertificate:           cfg.GetCertificate,
                                ^
../../../google.golang.org/grpc/credentials/credentials_util_pre_go17.go:69:32: error: reference to undefined field or method ‘ClientSessionCache’
   ClientSessionCache:       cfg.ClientSessionCache,
                                ^
../../../google.golang.org/grpc/credentials/credentials_util_pre_go17.go:72:32: error: reference to undefined field or method ‘CurvePreferences’
   CurvePreferences:         cfg.CurvePreferences,
                                ^
../../../google.golang.org/grpc/credentials/credentials_util_pre_go17.go:58:3: error: unknown field ‘GetCertificate’ in ‘tls.Config’
   GetCertificate:           cfg.GetCertificate,
   ^
# golang.org/x/net/http2/hpack
../../../golang.org/x/net/http2/hpack/huffman.go:14:20: error: reference to undefined identifier ‘sync.Pool’
 var bufPool = sync.Pool{
                    ^
../../../golang.org/x/net/http2/hpack/huffman.go:14:24: error: expected ‘;’ or newline after top level declaration
 var bufPool = sync.Pool{
                        ^
# golang.org/x/net/context/ctxhttp
../../../golang.org/x/net/context/ctxhttp/ctxhttp_pre17.go:36:5: error: reference to undefined field or method ‘Cancel’
  req.Cancel = cancel
     ^
# golang.org/x/oauth2/jws
../../../golang.org/x/oauth2/jws/jws.go:75:17: error: reference to undefined identifier ‘base64.RawURLEncoding’
   return base64.RawURLEncoding.EncodeToString(b), nil
                 ^
../../../golang.org/x/oauth2/jws/jws.go:93:16: error: reference to undefined identifier ‘base64.RawURLEncoding’
  return base64.RawURLEncoding.EncodeToString(b), nil
                ^
../../../golang.org/x/oauth2/jws/jws.go:113:16: error: reference to undefined identifier ‘base64.RawURLEncoding’
  return base64.RawURLEncoding.EncodeToString(b), nil
                ^
../../../golang.org/x/oauth2/jws/jws.go:124:25: error: reference to undefined identifier ‘base64.RawURLEncoding’
  decoded, err := base64.RawURLEncoding.DecodeString(s[1])
                         ^
../../../golang.org/x/oauth2/jws/jws.go:151:41: error: reference to undefined identifier ‘base64.RawURLEncoding’
  return fmt.Sprintf("%s.%s", ss, base64.RawURLEncoding.EncodeToString(sig)), nil
                                         ^
../../../golang.org/x/oauth2/jws/jws.go:174:33: error: reference to undefined identifier ‘base64.RawURLEncoding’
  signatureString, err := base64.RawURLEncoding.DecodeString(parts[2])

Go version is go version xgcc (Ubuntu 4.9.3-0ubuntu4) 4.9.3 linux/amd64

Running Linux Mint 17.3 Cinnamon

Anyone know what I'm doing wrong?

答案1

得分: 0

看起来你正在使用go cgo安装。在Linux Mint上,golang-go似乎是发行版的名称。

但我建议按照下面链接中提到的最新版本的go(或至少是go 1.5版本)进行安装,然后再尝试。

https://golang.org/doc/install

在进行golang-go安装之前,请先删除当前的安装。

英文:

Looks like you are using go cgo installation. On Linux mint golang-go seems to be the distribution name.

But I would suggest installing the latest version of go (or version go 1.5 atleast) as mentioned in the below link and try again.

https://golang.org/doc/install

Remove your current installation before proceeding with the golang-go installation.

huangapple
  • 本文由 发表于 2017年1月12日 16:39:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/41608477.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定