go get error - can't load package

2020-06-13 17:33发布

I am new to golang and I am trying to get a package but I get a strange error and can't seem to figure out what the problem is?

padlar@padlar:~/workspace-go$ echo $GOPATH
/home/padlar/workspace-go

padlar@padlar:~/workspace-go$ go get golang.org/x/oauth2
padlar@padlar:~/workspace-go$ ls ~/workspace-go/src/golang.org/x/oauth2/
    AUTHORS            google/            jwt_test.go        README.md          
    CONTRIBUTORS       internal/          LICENSE            transport.go       
    example_test.go    jws/               oauth2.go          transport_test.go  
    .git/              jwt.go             oauth2_test.go     .travis.yml        

padlar@padlar:~/workspace-go$ ls ~/workspace-go/pkg/linux_amd64/golang.org/x/oauth2
oauth2/   oauth2.a  
padlar@padlar:~/workspace-go$ ls ~/workspace-go/pkg/linux_amd64/golang.org/x/oauth2/
internal.a  jws.a
padlar@padlar:~/workspace-go$ go get github.com/golang/oauth2
can't load package: package github.com/golang/oauth2: code in directory /home/padlar/workspace-go/src/github.com/golang/oauth2 expects import "golang.org/x/oauth2"

1条回答
该账号已被封号
2楼-- · 2020-06-13 17:57

You are using go get on two different import paths. The new path,

go get golang.org/x/oauth2

and the old path

go get github.com/golang/oauth2

This confuses the Go tool chain. Consistently use the new import path

go get golang.org/x/oauth2
查看更多
登录 后发表回答