每日学习记录

1. 如果项目编译过程中出现 "package XXX is not in GOROOT” when building Golang project" 这样的问题,用go mod init 命令添加到项目到GOROOT中即可。

问题来了, go mod init究竟有什么作用?

官方文档中的说法是

The go mod init command creates a go.mod file to track your code's dependencies. So far, the file includes only the name of your module and the Go version your code supports. But as you add dependencies, the go.mod file will list the versions your code depends on. This keeps builds reproducible and gives you direct control over which module versions to use.

简单翻译过来就是,go mod 是一个包管理工具,包括了你需要的第三方的包的版本,如果需要升级某个第三方包的版本,修改go mod中对应包的版本号,然后go mod tidy命令,功能是add missing and remove unused modules。go.mod文件一旦创建后,它的内容将会被go toolchain全面掌控。go toolchain会在各类命令执行时,比如go get、go build、go mod等修改和维护go.mod文件。

go mod init 负责把当前路径设为goroot路径.

go.mod负责记录需求列表(用于构建依赖模块)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值