问题描述:使用vscode编写go语言时虽然可以正常运行但是总是有个错误非常难受,查了好多篇文章都不能解决,最后在微软官方文档找到了解决办法
错误提示:
Error loading workspace: packages.Load error: err: exit status 1: stderr: go: go.mod file not found in current directory or any parent directory; see 'go help modules'
解决方法:来源于微软官方文档为 Go 开发配置Visual Studio Code
其实并不复杂,只要在go文件所在文件夹内创建另一个用于创建根控制器的文件夹(文件夹名随意,这里是sample-app)
然后使用终端进入main目录,使用命令go mod init sample-app之后便会生成go.mod文件,然后就可以正常使用了