Go的模块管理Mod

  时至今日Go的版本已经来到了1.12 在1.11的时候Go正式推出了go mod 在此之前dep等第三方依赖工具百花齐放。go mod出来之后有助于像java的maven一样能够有一个比较统一的代码依赖管理。

  1.go mod有哪些命令:   

	download    download modules to local cache 
	edit        edit go.mod from tools or scripts 
	graph       print module requirement graph
	init        initialize new module in current directory
	tidy        add missing and remove unused modules
	vendor      make vendored copy of dependencies
	verify      verify dependencies have expected content
	why         explain why packages or modules are needed

  2.如何使用

    执行 go mod init会初始化一个mod管理的项目 在项目路径下会有两个文件go.mod go.sum 

//go.mod 示例 记录的是依赖管理
module resources-server

require (
	github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7 // indirect
	github.com/gin-gonic/gin v1.3.0
	github.com/go-yaml/yaml v2.1.0+incompatible
	github.com/golang/protobuf v1.2.0 // indirect
	github.com/json-iterator/go v1.1.5 // indirect
	github.com/mattn/go-isatty v0.0.4 // indirect
	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
	github.com/modern-go/reflect2 v1.0.1 // indirect
	github.com/ugorji/go/codec v0.0.0-20181116192919-e105254e6a51 // indirect
	gopkg.in/go-playground/validator.v8 v8.18.2 // indirect
	gopkg.in/yaml.v2 v2.2.1 // indirect
)

  

// go.sum 记录的是版本变更

github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7 h1:AzN37oI0cOS+cougNAV9szl6CVoj2RYwzS3DpUQNtlY=
github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s=
github.com/gin-gonic/gin v1.3.0 h1:kCmZyPklC0gVdL728E6Aj20uYBJV93nj/TkwBTKhFbs=
github.com/gin-gonic/gin v1.3.0/go.mod h1:7cKuhb5qV2ggCFctp2fJQ+ErvciLZrIeoOSOm6mUr7Y=
github.com/go-yaml/yaml v2.1.0+incompatible h1:RYi2hDdss1u4YE7GwixGzWwVo47T8UQwnTLB6vQiq+o=
github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=

  

  3.关于“墙”的问题

设置代理export GOPROXY=https://goproxy.io  在以后的版本可能会逐步取消go path 自己下载包安装比较麻烦 自行替换依赖也比较麻烦

  

上一篇:欧拉回路和欧拉路径


下一篇:The Euler function(欧拉函数预处理+素数筛+一维数组前缀和)