当前位置:网站首页>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 .
边栏推荐
- Principle of lazy loading of pictures
- Etcd database source code analysis - brief process of processing entry records
- 数据库基础知识
- ETCD数据库源码分析——处理Entry记录简要流程
- 【爬虫】数据提取之xpath
- Excel shortcut keys - always add
- 香港珠宝大亨,22亿“抄底”佐丹奴
- 推荐收藏:跨云数据仓库(data warehouse)环境搭建,这货特别干!
- 快解析——好用的内网安全软件
- S32 design studio for arm 2.2 quick start
猜你喜欢
法国学者:最优传输理论下对抗攻击可解释性探讨
phpcms付费阅读功能支付宝支付
French scholars: the explicability of counter attack under optimal transmission theory
Mit-6.824-lab4b-2022 (10000 word idea explanation - code construction)
【二叉树】节点与其祖先之间的最大差值
ETCD数据库源码分析——处理Entry记录简要流程
使用快解析搭建自己的minecraft服务器
Qt加法计算器(简单案例)
Actual combat simulation │ JWT login authentication
Jar批量管理小工具
随机推荐
高配笔记本使用CAD搬砖时卡死解决记录
List related knowledge points to be sorted out
The initial arrangement of particles in SPH (solved by two pictures)
香港珠宝大亨,22亿“抄底”佐丹奴
OSEK标准ISO_17356汇总介绍
A complete tutorial for getting started with redis: getting to know redis for the first time
使用快解析搭建自己的minecraft服务器
Using the uniapp rich text editor
LabVIEW中比较两个VI
Font design symbol combination multifunctional wechat applet source code
企业里Win10 开启BitLocker锁定磁盘,如何备份系统,当系统出现问题又如何恢复,快速恢复又兼顾系统安全(远程设备篇)
Redis:Redis的事务
ICML 2022 || 3DLinker: 用于分子链接设计的E(3)等变变分自编码器
Ffmpeg quick clip
Etcd database source code analysis - brief process of processing entry records
Qt个人学习总结
Financial markets, asset management and investment funds
取得PMP證書需要多長時間?
【二叉树】节点与其祖先之间的最大差值
快解析——好用的内网安全软件