当前位置:网站首页>Go step on the pit - no required module provides package: go mod file not found in current directory or any parent
Go step on the pit - no required module provides package: go mod file not found in current directory or any parent
2022-07-04 23:28:00 【Xiaoming's note warehouse】
background
Prepare to run the following code
package main
import (
"github.com/gin-gonic/gin"
)
func main() {
// Create a default routing engine
r := gin.Default()
// GET: Request mode ;/hello: The path of the request
// When the client uses GET Method request /hello When the path , Will execute the following anonymous function
r.GET("/hello", func(c *gin.Context) {
// c.JSON: return JSON Formatted data
c.JSON(200, gin.H{
"message": "Hello world!",
})
})
// start-up HTTP service , Default in 0.0.0.0:8080 Start the service
r.Run()
}
The result is wrong :
no required module provides package : go.mod file not found in current directory or any parent directory;
That is to say, the package of the imported module cannot be found
Try 1:
go get -u github.com/gin-gonic/gin
There is no effect
Online is basically this solution : perform :go env -w GO111MODULE=auto
But mine is already open , So exclude this solution .
Try 3: I built another project , Another running error result is found :
1.go:4:2: no required module provides package github.com/gin-gonic/gin; to add it:
go get github.com/gin-gonic/gin
Pay attention to the difference between the two error reports , This prompt go get github.com/gin-gonic/gin
It shows that the original project is lack of things , I compared it and found that the folder where the original project code is located is missing go.mod This file
Through research Go go.mod Detailed explanation _ The blog of Min Ming, the owner of Jiangdong flower -CSDN Blog _go.mod file
Got the solution
resolvent
Open the terminal in the error code folder , function
go mod init New module name
You can initialize go.mod, Run it like this
go get -u github.com/gin-gonic/gin
Just OK 了
summary
- Go.mod yes Golang1.11 The official package management tool newly introduced by the version is used to solve the problem that there is no place to record the specific version of the package , Facilitate the management of dependent packages .
- Go.mod It's really just a Modules, About Modules The official definition of is :Modules It's related Go Bag aggregate , Is the source code exchange and version control unit .go Command direct support Modules, Including logging and parsing dependencies on other modules .Modules Replace old based on GOPATH Methods , To specify which source files to use .
- Modules And traditional GOPATH Different , It is not necessary to include, for example src,bin Such subdirectories , A source directory or even an empty directory can be used as Modules, As long as it contains go.mod file .
边栏推荐
- S32 design studio for arm 2.2 quick start
- QT addition calculator (simple case)
- 蓝天NH55系列笔记本内存读写速度奇慢解决过程记录
- [kotlin] the third day
- 推荐收藏:跨云数据仓库(data warehouse)环境搭建,这货特别干!
- French scholars: the explicability of counter attack under optimal transmission theory
- LabVIEW中比较两个VI
- 如何报考PMP项目管理认证考试?
- PMP证书续证流程
- HMS core unified scanning service
猜你喜欢
实战模拟│JWT 登录认证
Docker镜像的缓存特性和Dockerfile
How long does it take to obtain a PMP certificate?
A mining of edu certificate station
Qualcomm WLAN framework learning (30) -- components supporting dual sta
45岁教授,她投出2个超级独角兽
D3.js+Three. JS data visualization 3D Earth JS special effect
Using the uniapp rich text editor
CTF竞赛题解之stm32逆向入门
OSEK standard ISO_ 17356 summary introduction
随机推荐
Docker镜像的缓存特性和Dockerfile
qt绘制网络拓补图(连接数据库,递归函数,无限绘制,可拖动节点)
华泰证券低佣金的开户链接安全吗?
【爬虫】数据提取之JSONpath
In the enterprise, win10 turns on BitLocker to lock the disk, how to back up the system, how to recover when the system has problems, and how to recover quickly while taking into account system securi
Redis:Redis的事务
go踩坑——no required module provides package : go.mod file not found in current directory or any parent
Redis getting started complete tutorial: hash description
Excel shortcut keys - always add
Redis: redis message publishing and subscription (understand)
Etcd database source code analysis - brief process of processing entry records
JS card style countdown days
LIst 相关待整理的知识点
Advantages of Alibaba cloud international CDN
认识ThreadPoolExecutor
Phpcms paid reading function Alipay payment
PICT 生成正交测试用例教程
蓝天NH55系列笔记本内存读写速度奇慢解决过程记录
刷题指南-public
企业里Win10 开启BitLocker锁定磁盘,如何备份系统,当系统出现问题又如何恢复,快速恢复又兼顾系统安全(远程设备篇)