在Linux Mint上获取OAuth2给我奇怪的错误

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?

doumi1884
doumi1884 main.go在我的主目录中,位于projects/golang/github.com/user/rental_api下。gopath设置为projects/golang文件夹,goroot为/usr
3 年多之前 回复
douyuefu1372
douyuefu1372 您将main.go放在哪里?您是否遵循此处提到的golang项目结构-golang.org/doc/code.html?
3 年多之前 回复

1个回答



好像您正在使用go cgo安装。 在Linux上,薄荷 golang-go </ code>似乎是发行名称。 </ p>

但是我建议按照以下链接中所述安装最新版本的 go </ code>(或至少为1.5)。 </ p>

https://golang.org/doc/install </ p>

在继续进行 golang-go </ code>安装之前,请删除当前安装。</ p>
</ div>

展开原文

原文

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.

dongmubi4444
dongmubi4444 抱歉,我花了几个月的时间才选择-我以为我已经选择了你
接近 3 年之前 回复
duanhuilao0787
duanhuilao0787 -对您有用吗?
3 年多之前 回复
dongqi8114
dongqi8114 我建议从golang.org进行安装。在GOROOT中添加安装目录的位置。 在您的PATH env变量中添加GOROOT。 还要确保cgo安装不在您的PATH中。
3 年多之前 回复
dongmei6426
dongmei6426 您的GOROOT显示什么?
3 年多之前 回复
dongxiong1941
dongxiong1941 通过删除usr / local / go卸载go,删除.profile和.bashrc中go lang env变量的引用,从golang.org下载页面重新安装最新版本的go ...在运行“ go version”时仍然得到相同的输出 -使用go env时,我得到GOTOOLDIR =“ / usr / lib / gccgo / tool” ...我应该卸载并使用sudo apt-get install golang-go吗?
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐