Go Module包管理工具

Go 1.11提出的新的包管理思路,支持用 模块 的方式看一个Go程序,用go.mod管理版本信息,其实基本是自动生成

1. 基本操作

 生成空的go.mod文件

go mod init <your module path>

 自动填写依赖,生成go.sum,这个主要为了记录曾经用过的以来,用版本的hash做记录

go build

    更改完后,查看当前依赖和版本 ===> 需要重新 go build(?

 

go list -m all
go list -m -version '可能是git上的链接' //查看过去版本号

    如果需要手动修改,用以下命令行

go mod edit -replace 'module name'

回退版本:

go get github.com/gin-gonic/[email protected] 获取之前版本,这样版本就回退了。。

go mod edit -require="github.com/gin-gonic/[email protected]"  + go tidy  更改依赖版本号,并下载对应包。。

升级版本:

go get -u

《?   

2. 其他命令

go mod tidy 

fetch all the dependencies that you need for testing in your module,会清除不需要的依赖

go mod why -m <module>

find out where any of your dependencies are used

go mod vendor

生成vendor目录

 

3. 代理

1.1时推出的新环境变量,为golang的代码仓库做镜像代理

如何配置:

配置环境变量 export GOPROXY=https://。。。。

proxy失败后,不会自动回源,因此可以用goc工具,

可用代理:

gocenter.io

 goproxy.io

猜你喜欢

转载自www.cnblogs.com/GW977/p/11091518.html