当前位置:网站首页>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/ginThere 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/ginJust 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 .
边栏推荐
- Redis:Redis消息的发布与订阅(了解)
- Phpcms paid reading function Alipay payment
- Why does infographic help your SEO
- [crawler] jsonpath for data extraction
- ICML 2022 | 3dlinker: e (3) equal variation self encoder for molecular link design
- 微软禁用IE浏览器后,打开IE浏览器闪退解决办法
- 法国学者:最优传输理论下对抗攻击可解释性探讨
- The caching feature of docker image and dockerfile
- Redis: redis message publishing and subscription (understand)
- Qt个人学习总结
猜你喜欢

Actual combat simulation │ JWT login authentication

JS card style countdown days

QT drawing network topology diagram (connecting database, recursive function, infinite drawing, dragging nodes)

Tweenmax emoticon button JS special effect

Observable time series data downsampling practice in Prometheus

Solution record of jamming when using CAD to move bricks in high configuration notebook

The difference between debug and release

一次edu证书站的挖掘

如何用快解析自制IoT云平台

debug和release的区别
随机推荐
Observable time series data downsampling practice in Prometheus
ETCD数据库源码分析——处理Entry记录简要流程
智力考验看成语猜古诗句微信小程序源码
Advantages of Alibaba cloud international CDN
Mit-6.824-lab4b-2022 (10000 word idea explanation - code construction)
Selected cutting-edge technical articles of Bi Ren Academy of science and technology
[Taichi] change pbf2d (position based fluid simulation) of Taiji to pbf3d with minimal modification
Phpcms paid reading function Alipay payment
LIst 相关待整理的知识点
MariaDB的Galera集群应用场景--数据库多主多活
PICT 生成正交测试用例教程
Chinese verification of JS regular expressions (turn)
Paddleocr tutorial
C language to quickly solve the reverse linked list
ECCV 2022 | 腾讯优图提出DisCo:拯救小模型在自监督学习中的效果
cout/cerr/clog的区别
heatmap. JS picture hotspot heat map plug-in
Hash table, hash function, bloom filter, consistency hash
端口映射和端口转发区别是什么
Pict generate orthogonal test cases tutorial