go依赖管理和获取golang/x等外面世界的包

go依赖管理和获取golang/x等外面世界的包

首先得更新到go1.11版本以上,支持go mod

go mod 是官方推荐的依赖管理工具,此后项目都不用写长长的 G O P A T H / s r c / ∗ ∗ ∗ . g i t / 了 , 而 且 项 目 也 不 用 放 到 GOPATH/src/***.git/了,而且项目也不用放到 GOPATH/src/.git/GOPATH里。

Go mod provides access to operations on modules.

Note that support for modules is built into all the go commands,
not just 'go mod'. For example, day-to-day adding, removing, upgrading,
and downgrading of dependencies should be done using 'go get'.
See 'go help modules' for an overview of module functionality.

Usage:

	go mod <command> [arguments]

The commands are:

	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

Use "go help mod <command>" for more information about a command.

用法就是现在源码目录使用go mod init PackName, 会在根目录创建go.mod,里面存放依赖关系.这时里面只有一条module PackName 的记录。

接下来是 go mod tidy, 会自动分析项目依赖,并下载到$GOPATH/pkg/mod 目录下,这些依赖都会携带版本号和sum值,所有项目也都会共用mod目录的包,不用在vendor下复制一堆了。

But 有个问题,就是golang/x/里的包现在也是带版本号和sum值的了,不想以前可以手动clone再复制这么简单了,所以找到一个神器,goproxy.io, 可以用自建的源也可以用他已经提供的,再环境里添加

export GOPROXY=https://goproxy.io

终于可以不用管golang/x了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值