go mod的使用

109 阅读1分钟
  1. 当modules功能启用时,依赖包的存放位置变更为$GOPATH/pkg,允许同一个package多个版本并存,且多个项目可以共享缓存的 module
  2. 初始化项目 在空文件夹内(我选的文件夹是Gone )输入
go mod init github.com/Gone

查看一下 go.mod文件

module github.com/Gone

go 1.19

go.mod 提供了module, require、replace和exclude 四个命令

  • module 语句指定包的名字(路径)
  • require 语句指定的依赖项模块
  • replace 语句可以替换依赖项模块
  • exclude 语句可以忽略依赖项模块

module起名前面加个github.com/的作用是,当把该项目发布到Github之后,如果有人需要使用,就可以使用:

go get github.com/Gone

参考大佬的博客