看我博客按照流程走就好了,核心就是环境变量配置
环境变量是已经配置了,我用的VS Code
@力揽狂澜:
package main //表示main包 (每一个go文件,必须隶属于一个包)
import "fmt" //表示导入fmt包(打印相关)
func main() { //表示main函数
fmt.Println("Hello, World!") //表示在控制台输出
}
//你少入口函数main函数呀
@小小咸鱼YwY: C:\Users\hp>go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\hp\AppData\Local\go-build
set GOENV=C:\Users\hp\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\hp\go\bin\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\hp\go\bin
set GOPRIVATE=
set GOPROXY=https://goproxy.io,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
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\hp\AppData\Local\Temp\go-build662672126=/tmp/go-build -gno-record-gcc-switches
可以加个QQ吗,我发图
缺少go.mod文件,go mod init命令
C:\Users\hp>go mod init
go: cannot determine module path for source directory C:\Users\hp (outside GOPATH, module path must be specified)
Example usage:
'go mod init example.com/m' to initialize a v0 or v1 module
'go mod init example.com/m/v2' to initialize a v2 module
Run 'go help mod init' for more information.
接下是应该...
@力揽狂澜: go mod init 后面加上模块路径,比如下面的例子:
go mod init example.com/m
@墟烟: C:\Users\hp>go mod init example.com/m
go mod init: go.mod already exists
按照教程来,不清楚缺少的模块
//-------------
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello, playgrount")
}
//-------------
go: cannot find main module; see 'go help modules'
exit status 1
Process exiting with code: 1
@力揽狂澜: 从错误上看,go.mod已经存在,删了文件重新敲命令试试看