0

我开启了GO111MODULE=on,在使用Go Get -u安装包的时候,会安装到PGK目录下,但是安装后无法使用

Go 版本 go1.15.6 Windows/amd64

go.mod 文件

module github.com/xanzy/go-gitlab

go 1.15

去环境

E:\code\awesomeProject2\src>go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=D:\Go\bin
set GOCACHE=C:\Users\code\AppData\Local\go-build
set GOENV=C:\Users\code\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=E:\code\awesomeProject2\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=E:\code\awesomeProject2
set GOPRIVATE=
set GOPROXY=https://mirrors.aliyun.com/goproxy/,direct
set GOROOT=D:\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=D:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=E:\code\awesomeProject2\src\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\guji\AppData\Loc
al\Temp\go-build895842770=/tmp/go-build -gno-record-gcc-switches

go build gitlab_merge_requests.go 我得到了错误

package github.com/xanzy/go-gitlab
imports github.com/xanzy/go-gitlab: import cycle not allowed

这是我的代码

package main

import (
"log"
"net/http"
"net/http/httptest"
"github.com/xanzy/go-gitlab"
)



var (
Token = "XXXXXX" // token information
url = "https://xxxxx" // gitlab URL
)

func setup() (*http.ServeMux, *httptest.Server, *gitlab.Client) {

// mux is the HTTP request multiplexer used with the test server.

mux := http.NewServeMux()



// server is a test HTTP server used to provide mock API responses.

server := httptest.NewServer(mux)



// client is the Gitlab client being tested.

client := gitlab.NewClient(nil, token)
client.SetBaseURL(url)


return mux, server, client

}



func main(){
_, _, client := setup()


users, _, err := client.Users.ListUsers(&gitlab.ListUsersOptions{})
if err ! = nil {

panic(err)

}

for _, user := range users {
log.Println(user.Username, user.Name, user.CreatedAt.Format("2006-01-02"))

}
}

我刚学Golang,谁能帮帮我?

4

2 回答 2

2

你的 go.mod 文件说你的模块被命名为github.com/xanzy/go-gitlab. 当您尝试导入该路径时,Go 认为您的包正在尝试导入自身,这是不可能的,并引发错误。

删除你的 go.mod 并使用你自己的模块路径重新运行go mod init(如果你有一个 repo,使用它,如果你从不打算与任何人共享它,你可以使用任何你喜欢的东西)。然后你就可以go get正确了。

于 2021-03-26T03:25:32.157 回答
0

import cycle not allowed告诉我你有进口的循环引用。A 进口 B,B 进口 A,甚至 A 进口 A。

于 2021-03-26T03:25:07.177 回答