• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

gomod

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

golang 终于出官方版本管理机制,名为 go modules

初体验

使用前:

# 先升级 golang 到 1.11 版本,然后
export GO111MODULE=on

在项目github.com/humboldt-xie/test-mod下,通过go mod init

go mod init

然后会在当前项目目录下出现 go.mod 文件,内容为:

module github.com/humboldt-xie/test-mod

编辑代码 main.go

package main

import (
	"fmt"
	"github.com/humboldt-xie/hlib/vmap"
)

func main() {
	vmap := vmap.NewVMap()
	fmt.Println("vim-go", vmap)
}

引用一个包

然后,直接运行go build ./

➜  go build ./
go: finding github.com/humboldt-xie/hlib/vmap latest
go: finding github.com/humboldt-xie/hlib latest

这时,会自动加载依赖包,并编译通过

这时,多了一个文件go.sum,并且go.mod 也被修改了

go.mod 则是描述直接依赖包(相当于glide.yaml)

go.sum 则是描述依赖树锁定(相当于glide.lock)

查看go.mod 文件内容,这时变为了

module github.com/humboldt-xie/test-mod

require github.com/humboldt-xie/hlib v0.0.0-20180903073735-6738efa10c3a

go.sum 内容为

github.com/humboldt-xie/hlib v0.0.0-20180903073735-6738efa10c3a h1:GgiozN6lA73wd7mQbJUdiEzW9CoBJM1Ey8A3G8RbsCo=
github.com/humboldt-xie/hlib v0.0.0-20180903073735-6738efa10c3a/go.mod h1:Zdztzq6jaF9E1ZbVz6g5Kf/Thx4/guqFB3gxAkcNkGs=
github.com/timtadh/data-structures v0.5.2 h1:yGrL+5Tf5mwRDPGnKwLeLOvfmoDsuKiMRmpETgGq+4w=
github.com/timtadh/data-structures v0.5.2/go.mod h1:9R4XODhJ8JdWFEI8P/HJKqxuJctfBQw6fDibMQny2oU=

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

存储

go mod 下载的库,都存储在

$GOPATH/pkg/mod/cache 下

总结

使用go mod 总共分为两步:

go mod init

go build ./

十分简单

 

来源:https://www.wafunny.com/blog/go/mod.html


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
GO-CFAR算法————GO-CFAR处理器以及几种近似的GO-CFAR处理器发布时间:2022-07-10
下一篇:
eclipse安装go插件发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap