Closed Lesekater closed 2 years ago
Do you have a small snippet that reproduces this ?
Sure, to reproduce:
foo@bar:~$ go mod init example.com/SptfAuthTest
foo@bar:~$ go get github.com/zmb3/spotify/v2
then copy the authenticate.go into the same folder, which needs
foo@bar:~$ go get github.com/zmb3/spotify/v2/auth@v2.0.0
and that results for me in
package github.com/zmb3/spotify/v2/auth
imports github.com/zmb3/spotify/v2/auth: import cycle not allowed
➜ ~ mkdir test
➜ ~ cd ./test
➜ test go mod init example.com/SptfAuthTest
go: creating new go.mod: module example.com/SptfAuthTest
➜ test ls
go.mod
➜ test go get github.com/zmb3/spotify/v2
go get: added github.com/zmb3/spotify/v2 v2.0.0
➜ test nano ./authenticate.go
➜ test go run ./authenticate.go
../go/pkg/mod/github.com/zmb3/spotify/v2@v2.0.0/auth/auth.go:10:2: missing go.sum entry for module providing package golang.org/x/oauth2 (imported by github.com/zmb3/spotify/v2/auth); to add:
go get github.com/zmb3/spotify/v2/auth@v2.0.0
➜ test go get github.com/zmb3/spotify/v2/auth@v2.0.0
➜ test go run ./authenticate.go
Please log in to Spotify by visiting the following page in your browser: https://accounts.spotify.com/authorize?client_id=&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fcallback&response_type=code&scope=user-read-private&state=abc123
Hmm, I'm struggling to reproduce this, perhaps related to your Go version or your go versions configuration ?
Okay, I solved it: I don't know how or why, but in my go cache I had the client credentials exaple file for the auth file in the spotifyauth package. And that of course imported spotifyauth, which created an import cycle.
For anyone else running into this problem - just delete the pkg folder in your $GOPATH/ home folder and then run go get [...]
again.
If I understand correctly i have to import spotifyauth from "github.com/zmb3/spotify/v2/auth" like in the example. But if I try to copy the exact code from the example into any other place I get "import cycle not allowed"