当前位置:网站首页>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 .
边栏推荐
- HMS core unified scanning service
- MP advanced operation: time operation, SQL, querywapper, lambdaquerywapper (condition constructor) quick filter enumeration class
- 法国学者:最优传输理论下对抗攻击可解释性探讨
- JS 3D explosive fragment image switching JS special effect
- After Microsoft disables the IE browser, open the IE browser to flash back the solution
- Redis:Redis消息的发布与订阅(了解)
- MariaDB的Galera集群应用场景--数据库多主多活
- The input of uniapp is invalid except for numbers
- Examples of time (calculation) total tools: start time and end time of this year, etc
- French scholars: the explicability of counter attack under optimal transmission theory
猜你喜欢

QT personal learning summary

Selected cutting-edge technical articles of Bi Ren Academy of science and technology

Redis introduction complete tutorial: List explanation

qt绘制网络拓补图(连接数据库,递归函数,无限绘制,可拖动节点)

Using the uniapp rich text editor

Qt加法计算器(简单案例)

Mit-6.824-lab4b-2022 (10000 word idea explanation - code construction)

ICML 2022 | 3dlinker: e (3) equal variation self encoder for molecular link design

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

45 year old professor, she threw two super unicorns
随机推荐
MariaDB's Galera cluster application scenario -- multi master and multi active databases
推荐收藏:跨云数据仓库(data warehouse)环境搭建,这货特别干!
Combien de temps faut - il pour obtenir un certificat PMP?
[ODX studio edit PDX] -0.3- how to delete / modify inherited elements in variant variants
壁仞科技研究院前沿技术文章精选
debug和release的区别
PaddleOCR教程
MariaDB的Galera集群-双主双活安装设置
Hash table, hash function, bloom filter, consistency hash
[crawler] jsonpath for data extraction
Redis: redis transactions
[JS] - [dynamic planning] - Notes
股票账户佣金怎么调低,炒股佣金怎么调低网上开户安全吗
ICML 2022 | 3dlinker: e (3) equal variation self encoder for molecular link design
go踩坑——no required module provides package : go.mod file not found in current directory or any parent
Servlet+JDBC+MySQL简单web练习
French scholars: the explicability of counter attack under optimal transmission theory
[JS] - [sort related] - Notes
Phpcms paid reading function Alipay payment
Chinese verification of JS regular expressions (turn)