gomod用来对包进行治理,在Go v1.13默认开启。
初始化
mkdir ~/goPrj/gomodTestgo mod init gotest.com/v1
在根目录下会生成一个go.mod文件
增加测试代码,生成新文件gintest.go
package mainimport ( "net/http" "github.com/gin-gonic/gin")func main() { ginServ := gin.Default() ginServ.Any("/higin", WebRoot) ginServ.Run(":8888")}func WebRoot(context *gin.Context) { context.String(http.StatusOK, "hello, world")}
应用了gin,如果执行
go run gintest.go
命令,会主动下载Gin
在 go.mod文件中会新增咱们须要的Gin
下载所有依赖
go mod download
移除不须要的依赖包
go mod tidy
移除指定的依赖包
go mod edit --droprequire=packagepath
我的项目迁徙合并
倒入合并完我的项目后执行 go mod init会生成新的go.mod文件。
执行 go get ./... 下载所有依赖包go mod initgo get ./...
公布新版本
go mod edit --module=yourpackagename
能够看到此时版本曾经变到v2.