想知道更多关于区块链技术知识,请百度【链客区块链技术问答社区】

    链客,有问必答!

govendor依赖包管理1111

golang工程的依赖包经常使用go get命令来获取,例如:go get github.com/kardianos/govendor ,会将依赖包下载到GOPATH的路径下。

常用的依赖包管理工具有godep,govendor等,在Golang1.5之后,Go提供了GO15VENDOREXPERIMENT环境变量(Go 1.6版本默认开启该环境变量),用于将go build时的应用路径搜索调整成为当前项目目录/vendor 目录方式。通过这种形式,我们可以实现类似于 godep 方式的项目依赖管理。


#v1.0.9

wget http://blob.wae.haplat.net/golang/govendor-v1.0.9.linux-amd64.tar.gz

tar zxvf govendor-v1.0.9.linux-amd64.tar.gz

rm /usr/bin/govendor && mv govendor /usr/bin


#进入到项目目录

cd /path/to/your/project


#初始化vendor目录

govendor init



#将GOPATH中本工程使用到的依赖包自动移动到vendor目录中

#说明:如果本地GOPATH没有依赖包,先go get相应的依赖包

govendor add +external

或使用缩写: govendor add +e


# Update a package to latest, given any prior version constraint

govendor fetch golang.org/x/net/context



#使用HTTP协议

govendor fetch -insecure [url]


# Specify a specific version or revision to fetch

govendor fetch golang.org/x/net/context@a4bbce9fcae005b22ae5443f6af064d80a6f5a55

govendor fetch golang.org/x/net/context@v1   # Get latest v1.*.* tag or branch.

govendor fetch golang.org/x/net/context@=v1  # Get the tag or branch named "v1".


# Update packages from $GOPATH.

govendor update golang.org/x/net/context

govendor remove [pkg]