首页 > 其他分享 >vscode 错误 go: go.mod file not found in current directory or any parent directory; see 'go help

vscode 错误 go: go.mod file not found in current directory or any parent directory; see 'go help

时间:2023-12-21 14:46:40浏览次数:24  
标签:help parent gosrc modules directory go mod

前言

安装VSCODE 后,新建立的GO文件按F5出错。go: go.mod file not found in current directory or any parent directory; see 'go help modules'

处理步骤

开启go modules功能

命令行输入 go env -w GO111MODULE=on

建立src目录

比如我程序文件夹名为 gosrc,则目录为
gosrc
|_src 放源文件

初始化Go moudle

在项目根目录下,初始化Go moudle
命令行输入 go mod init gosrc
输入完成后,根目录下会多一个gosrc.mod的文件

建立GO文件

建立一个测试文件 如test.go,输入完代码后按F5运行,程序应该就可正确输出“hello world” 了.

`golang

package main
func main() {
print("hello world")
}

`

标签:help,parent,gosrc,modules,directory,go,mod
From: https://www.cnblogs.com/xueweil/p/16559169.html

相关文章

  • 无涯教程-Go - 函数闭包
    Go编程语言支持可以充当函数闭包的匿名函数,当我们要内联定义函数而不传递任何名称时,将使用匿名函数。在我们的示例中,我们创建了一个函数getSequence(),该函数返回另一个函数,此函数的目的是关闭上层函数的变量i形成闭包。如-packagemainimport"fmt"funcgetSequence()func......
  • permify google zanzibar 类似的开源授权服务实现
    permifygooglezanzibar类似的开源授权服务实现,openfga也是一个类似的开源实现参考架构从下图可以看出permify主要包含了四个组件,PermissionServer,RelationshipServer,SchemaServer,WatchServer说明目前不少开源的授权认证方案,都会基于配置定义的模式开发(schema)比较灵活......
  • 无涯教程-Go - Function as Value函数
    在下面的示例中,我们使用函数定义初始化了一个变量,该函数变量的目的只是使用内置的math.sqrt()函数。如-packagemainimport("fmt""math")funcmain(){/*声明一个函数变量*/getSquareRoot:=func(xfloat64)float64{returnmath.Sqrt(x)}/*......
  • 【Django】加密 settings.py文件中的数据库密码
    1.使用fromcryptography.fernetimportFernet第三方库pip3installcryptography2.Fernet的使用fromcryptography.fernetimportFernet#生成加密密钥key=Fernet.generate_key()#创建Fernet对象fernet=Fernet(key)#要加密的原始数据message=b"Hell......
  • Typora+PicGo 搭建免费图床
    前言对于经常写文章的人来说图片的管理一直是一个比较头疼的问题,最好的解决方案就是搭建一个图床,写文章的时候直接把图片上传上去,只要拿到链接在哪都能访问。如果还是免费的,是不是爽飞了。来试一下吧极力推荐:Typora+PicGo+SM.MS为什么选SM.MS:七牛云https收费、又拍云需要......
  • 【go】Go (Golang) 语言-Golang 定时器Timer和Ticker、time.AfterFunc、time.NewTicke
    Golang定时器Timer和TickerGolang定时器包括:一次性定时器(Timer)和周期性定时器(Ticker)。编程中经常会通过timer和ticker、AfterFunc定时器NewTicker是设定每隔多长时间触发的,是连续触发,而计时器NewTimer是等待多长时间触发的,只触发一次,两者是不同的。等待时间函数AfterFunc是......
  • 无涯教程-Go - for 循环函数
    for循环是一个重复控制结构,它允许您编写一个需要执行特定次数的循环。for-语法Go编程语言中for循环的语法为-for[condition|(init;condition;increment)|Range]{statement(s);}for-示例packagemainimport"fmt"funcmain(){varbint=15......
  • 无涯教程-Go - select 语句函数
    Go编程语言中select语句的语法如下-select{casecommunicationclause:statement(s);casecommunicationclause:statement(s);/*你可以有任意数量的case语句*/default:/*可选*/statement(s);}select-示例packag......
  • gorm 阅读3
    gorm相互关联//ConfigGORMconfigtypeConfigstruct{---------- Dialector-------- callbacks*callbacks cacheStore*sync.Map}//DBGORMDBdefinitiontypeDBstruct{ *Config Errorerror RowsAffectedint64 Statement*Statement......
  • 无涯教程-Go - switch 语句函数
    switch语句允许针对值列表对变量进行相等性测试。switch-语法Go编程语言中expressionswitch语句的语法如下-switch(boolean-expressionorintegraltype){caseboolean-expressionorintegraltype:statement(s);caseboolean-expressionori......