[部署日记]GO在Visual Studio Code初次运行时提示go: go.mod file not found in current directory or any parent directory; see 'go help modules'

我裂开,一波未平一波又起...

按照MS教程上填写

package main

import "fmt"

func main() {
    fmt.Println("Hello World!")
}

然后无脑搜索教程,其中修改了launch.json无济于事,按理来说新手入门的话应该VSC的配置文件是不需要修改的。


翻了下文档,发现是  跳  过  新  手  教  程  的  错  误  玩  法

在新建新GO项目后,要在当前文件夹执行

go mod init {项目名}

然后进入项目文件夹,执行

go build

最后回到VSC运行提示:

Hello World!
Process exiting with code: 0

完事

原文地址:https://www.cnblogs.com/cela/p/go_go_1_S1.html