Golang Package Management tool (i) the use of the Govendor

Source: Internet
Author: User

This personal blog address is: http://www.huweihuang.com/article/golang/govendor-usage/
This personal blog address is: https://huweihuang.net/article/golang/govendor-usage/

More Golang package Management tools Reference
-Use of DEP
-Use of glide
-Use of Govendor

1. Govendor Introduction

Golang project dependencies are often obtained using the go get command, for example: Go get Github.com/kardianos/govendor, which will download the dependent package to GOPATH the path.

The common Dependency Package management tool has godep , and govendor so on, after Golang1.5, GO provides GO15VENDOREXPERIMENT environment variables (the Go 1.6 version opens the environment variable by default ), which adjusts the application path search for Go build to be the 当前项目目录/vendor directory mode. In this form, we can implement godep project-dependent management similar to the way it is.

2. Installation and use

2.1. Installation

-u-v github.com/kardianos/govendor

2.2. Use

#进入到项目目录cd /home/gopath/src/mytool#初始化vendor目录govendor init#查看vendor目录[root@CC54425A mytool]# lscommands  main.go  vendor  mytool_test.sh#将GOPATH中本工程使用到的依赖包自动移动到vendor目录中#说明:如果本地GOPATH没有依赖包,先go get相应的依赖包#Go 1.6以上版本默认开启 GO15VENDOREXPERIMENT 环境变量,可忽略该步骤。#通过设置环境变量 GO15VENDOREXPERIMENT=1 使用vendor文件夹构建文件。#可以选择 export GO15VENDOREXPERIMENT=1 或 GO15VENDOREXPERIMENT=1 go build 执行编译export GO15VENDOREXPERIMENT=1

2.3. Description

govendorJust to manage the dependencies of the project, if GOPATH there is no dependency package for the project itself, it needs to be go get downloaded to Gopath and then govendor add +external copied to the vendor directory. Go 1.6 or later the Go15vendorexperiment environment variable is turned on by default .

3. Govendor using commands

[root@cc54425a Mytool]# GovendorGovendor (v1. 0. 8):RecordDependencies and Copy  intoVendor folder-govendor-licenses Show Govendor ' s licenses. -versionShow Govendorversion-cpuprofile 'file' Writes a CPU profile to'file' forDebugging. -memprofile 'file' Writes a heap profile to'file' forDebugging. Sub-commands Init Create the "Vendor"Folder and  the "Vendor.json" file.ListList andFilter existing dependencies andPackages. Add Add Packages from$GOPATH. Update update packages from$GOPATH. Remove Remove Packages from  theVendor folder. Status Lists any packages missing, out- of-Date,orModified locally. Fetch ADD NEWorUpdate Vendor Folder Packages fromRemote Repository. Sync Pull Packages intoVendor folder fromRemote Repository withRevisions fromVendor.jsonfile. Migrate Move Packages fromA Legacy tool to  theVendor folder withMetadata.GetLike"Go get"  butCopies dependencies intoA"Vendor"Folder. License List discovered licenses for  the givenStatusorImport paths. Shell Run A"Shell"  toMake multiple sub-commands more efficient forLarge projects. Go tool commands thatIs wrapped:"+status"Package selection may used withthem FMT, build, install, clean, test, vet, generate, Toolstatus Types +Local(l) PackagesinchYour project +external (e) referenced packagesinchGopath but  not inchCurrent Project +vendor (v) packagesinch  theVendor folder +STD (s) packagesinch  theStandard library +excluded (x) external packages explicitly excluded fromVendoring +unused (U) packagesinch  theVendor folder, butUnused +missing (m) referenced packages but  notFound +program (p) package isA main package +outside +external +missing +all +all packages Status can referenced byTheir initial letters. Package specifier <path>[::<origin>][{/...| /^}][@[<version-spec>]]ignoring files withBuild tags,orExcluding packages fromBeing vendored:the"Vendor.json" file containsAstringField named"Ignore". It MaycontainASpaceSeparatedList  ofBuild tags toIgnore when listing andCopying files. ThisListMay alsocontainPackage prefixes (containing a"/", possibly as  Last character) toExclude when copying filesinch  theVendor folder. If"foo/"AppearsinchThis field, ThenPackage"foo"  andAll itsSub-packages ("Foo/bar", ...) would be excluded ( butPackage"Bar/foo"Would not). By default theinit command adds the "Test"Tag to  theIgnoreList. If using Go1. 5, ensure go15vendorexperiment=1  is Set.

4. Vendor.json

Govendor configuration file, record the list of dependent packages.

{    "Comment":"",    "Ignore":"Test",    " Package":[{"checksumSHA1": "ugalsicr4r7354vvkunnh7y/r/4=", "path": 
    
      "Github.com/urfave/cli", "
     revision": 
     "b99aa811b4c1dd84cc6bccb8499c82c72098085a", "
     revisiontime": 
     "2017-08-04t09:34:15z"        }]
    ,    "RootPath":"Mytool"}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.