我第一次安装了 Golang 并遇到了go.mod file not found in current directory or any parent directory
错误。
但我正在处理<GOPATH>/src
目录。仅当当前工作目录位于 GOPATH 之外时才需要 go.mod 吗?
这里有详细信息
去版本:go version go1.16.4 windows/amd64
去环境:
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\<userName>\AppData\Local\go-build
set GOENV=C:\Users\<userName>\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\<userName>\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\<userName>\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.16.4
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
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\<userName>\AppData\Local\Temp\go-build4258913208=/tmp/go-build -gno-record-gcc-switches
工作目录:C:\Users\<userName>\go\src\main.go
代码 :
package main
import "fmt"
func main() {
fmt.Println("HELLO")
}
和错误:
go: go.mod file not found in current directory or any parent directory; see 'go help modules'
Build process exiting with code: 1 signal: null
ps 我正在使用VS Code