简体   繁体   English

go 获取返回 go:标志需要一个参数:-mod

[英]go get returns go: flag needs an argument: -mod

I have updated my go version from go1.12.4 to go1.13.4.我已将我的 go 版本从 go1.12.4 更新到 go1.13.4。 I have created a project and initialized it with go mod init myproject creating a go.mod file with the information:我创建了一个项目并使用go mod init myproject创建了一个go.mod文件,其中包含以下信息:

module myproject

go 1.13

When I try to download a dependency当我尝试下载依赖项时

 go get github.com/kelseyhightower/envconfig

It returns the following message:它返回以下消息:

go: flag needs an argument: -mod (from $GOFLAGS)
usage: go get [-d] [-t] [-u] [-v] [-insecure] [build flags] [packages]
Run 'go help get' for details.

I have reviewed the doc from golang modules wiki and from its github issues but couldn't find any solution.我已经查看了golang modules wiki及其github 问题的文档,但找不到任何解决方案。

I have downgraded to go1.12.13 version, but I still have the same problem.我已经降级到go1.12.13版本,但我仍然有同样的问题。

My go env variables are:我的go env变量是:

GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/user/.cache/go-build"
GOENV="/home/usser/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/user/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build555598313=/tmp/go-build -gno-record-gcc-switches"

Thank you so much太感谢了

在此处输入图像描述

I think the problem is with you IDE: Goland我认为问题出在你 IDE:Goland

Use go env in the terminal在终端中使用go env

Your will see a env value called GOFLAGS, that is the problem您将看到一个名为 GOFLAGS 的 env 值,这就是问题所在

Just unset the env value by using unset GOFLAGS只需使用unset GOFLAGS取消设置 env 值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM