Go Get OAuth2 在 Linux Mint 上给我奇怪的错误

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: 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版本为go版本xgcc(Ubuntu4.9.3-0ubuntu4)4.9.3linux/amd64

运行 Linux 薄荷 17.3 肉桂色

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

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

但我建议安装下面提到的 go 的最新版本(或版本至少为 1.5),然后重试。

https://golang.org/doc/install

在继续 golang-go 安装之前删除当前安装。