当前位置:网站首页>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 .
边栏推荐
- Servlet+jdbc+mysql simple web exercise
- Redis: redis message publishing and subscription (understand)
- Docker镜像的缓存特性和Dockerfile
- MariaDB's Galera cluster application scenario -- multi master and multi active databases
- SPH中的粒子初始排列问题(两张图解决)
- 如何报考PMP项目管理认证考试?
- 高通WLAN框架学习(30)-- 支持双STA的组件
- Redis:Redis的事务
- Network namespace
- Solution record of jamming when using CAD to move bricks in high configuration notebook
猜你喜欢

How long does it take to obtain a PMP certificate?

Hash table, hash function, bloom filter, consistency hash

Actual combat simulation │ JWT login authentication

phpcms付费阅读功能支付宝支付

OSEK标准ISO_17356汇总介绍

Stm32 Reverse Introduction to CTF Competition Interpretation

Redis:Redis消息的发布与订阅(了解)

如何在外地外网电脑远程公司项目?

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

MariaDB的Galera集群应用场景--数据库多主多活
随机推荐
Instructions for go defer
Meet ThreadPoolExecutor
Tweenmax emoticon button JS special effect
取得PMP证书需要多长时间?
Using the uniapp rich text editor
机器人强化学习——Learning Synergies between Pushing and Grasping with Self-supervised DRL (2018)
金融市场,资产管理与投资基金
C语言快速解决反转链表
蓝天NH55系列笔记本内存读写速度奇慢解决过程记录
cout/cerr/clog的区别
法国学者:最优传输理论下对抗攻击可解释性探讨
ScriptableObject
French scholars: the explicability of counter attack under optimal transmission theory
Principle of lazy loading of pictures
Hong Kong Jewelry tycoon, 2.2 billion "bargain hunting" Giordano
uniapp 除了数字,其他输入无效
Application of machine learning in housing price prediction
用快解析内网穿透实现零成本自建网站
Network namespace
Basic use and upgrade of Android native database