使用govendor管理Golang项目依赖

前端之家收集整理的这篇文章主要介绍了使用govendor管理Golang项目依赖前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1、安装govendor

  1. go get -u -v github.com/kardianos/govendor

2、init

在项目根目录,比如我这里是tap项目,那就是进入tap目录,执行init命令

  1. govendor init
  2. ls
  3. cd vendor/
  4. ls


这个 vendor.json 会类似 godep 工具中的描述文件版本的功能

3、执行命令将当前应用必须的文件包含进来

  1. govendor add +external

4、vendor.json

vendor.json内容如下:

  1. {
  2. "comment": "","ignore": "test","package": [ { "checksumSHA1": "Ufix4JjY69s87o5ftKQ39OcxvTU=","path": "github.com/Shopify/sarama","revision": "2fd980e23bdcbb8edeb78fc704de0c39a6567ffc","revisionTime": "2017-06-30T17:40:37Z" },{ "checksumSHA1": "sUP5RbqwDFzHiW538NBTJ3c57aw=","path": "github.com/bsm/sarama-cluster","revision": "f1ef2fda9bccc377dad24d7f7522d46b6a9a817b","revisionTime": "2017-07-31T13:08:41Z" },{ "checksumSHA1": "GcIrB1ug6mS8aG73v1KtlHfva9Q=","path": "github.com/davecgh/go-spew/spew","revision": "adab96458c51a58dc1783b3335dcce5461522e75","revisionTime": "2017-07-11T18:34:51Z" },{ "checksumSHA1": "o0psFRtB8EoelTAEhJSqrtXdwJY=","path": "github.com/eapache/go-resiliency/breaker","revision": "b1fe83b5b03f624450823b751b662259ffc6af70","revisionTime": "2017-06-07T16:36:15Z" },{ "checksumSHA1": "jZ/Z0i7G8a+9GQ7uOzUbLI/FubU=","path": "github.com/eapache/go-xerial-snappy","revision": "bb955e01b9346ac19dc29eb16586c90ded99a98c","revisionTime": "2016-06-09T14:24:08Z" },{ "checksumSHA1": "Jv+5MP/HXSnx830En3Iwmj9v7g0=","path": "github.com/eapache/queue","revision": "44cc805cf13205b55f69e14bcb69867d1ae92f98","revisionTime": "2016-08-05T00:47:13Z" },{ "checksumSHA1": "OV+/R43DDDJ/Gxrx9oQob/K7sL0=","path": "github.com/golang/snappy","revision": "553a641470496b2327abcac10b36396bd98e45c9","revisionTime": "2017-02-15T23:32:05Z" },{ "checksumSHA1": "imr1t7r6P5Bz7DGR2sxDymLWo7w=","path": "github.com/pierrec/lz4","revision": "5a3d2245f97fc249850e7802e3c01fad02a1c316","revisionTime": "2017-05-19T17:06:25Z" },{ "checksumSHA1": "ieRRw3MpbPjA3z2MJVHDsC9jkjc=","path": "github.com/pierrec/xxHash/xxHash32","revision": "a0006b13c722f7f12368c00a3d3c2ae8a999a0c6","revisionTime": "2017-07-14T08:24:55Z" },{ "checksumSHA1": "DIjooF5+DLH5JSOjqnBlfNh9dFU=","path": "github.com/rcrowley/go-metrics","revision": "1f30fe9094a513ce4c700b9a54458bbb0c96996c","revisionTime": "2016-11-28T21:05:44Z" },{ "checksumSHA1": "fAm2yk7tTesaQ5ivVUPjTpKlxdo=","path": "github.com/sirupsen/logrus","revision": "95cd2b9c79aa5e72ab0bc69b7ccc2be15bf850f6","revisionTime": "2017-11-18T12:42:23Z" },{ "checksumSHA1": "X1NTlfcau2XcV6WtAHF6b/DECOA=","path": "golang.org/x/crypto/ssh/terminal","revision": "94eea52f7b742c7cbe0b03b22f0c4c8631ece122","revisionTime": "2017-11-28T01:43:40Z" },{ "checksumSHA1": "B2t4JjkjyoUINOnKXviNypvgWpo=","path": "golang.org/x/sys/unix","revision": "bf42f188b9bc6f2cf5b8ee5a912ef1aedd0eba4c","revisionTime": "2017-11-10T14:41:19Z" },{ "checksumSHA1": "ck5uxoEeMDUL/QqPvGvBmcbsJzg=","path": "golang.org/x/sys/windows","revisionTime": "2017-11-10T14:41:19Z" } ],"rootPath": "git.XXX.net/monitor/tap" }

5、govendor –help

  1. $ govendor --help
  2. govendor (v1.0.9): record dependencies and copy into vendor folder
  3. -govendor-licenses Show govendor's licenses.
  4. -version Show govendor version
  5. -cpuprofile 'file' Writes a cpu profile to 'file' for debugging.
  6. -memprofile 'file' Writes a heap profile to 'file' for debugging.
  7.  
  8. Sub-Commands
  9.  
  10. init Create the "vendor" folder and the "vendor.json" file.
  11. list List and filter existing dependencies and packages.
  12. add Add packages from $GOPATH.
  13. update Update packages from $GOPATH.
  14. remove Remove packages from the vendor folder.
  15. status Lists any packages missing,out-of-date,or modified locally.
  16. fetch Add new or update vendor folder packages from remote repository.
  17. sync Pull packages into vendor folder from remote repository with revisions
  18. from vendor.json file.
  19. migrate Move packages from a legacy tool to the vendor folder with Metadata.
  20. get Like "go get" but copies dependencies into a "vendor" folder.
  21. license List discovered licenses for the given status or import paths.
  22. shell Run a "shell" to make multiple sub-commands more efficient for large
  23. projects.
  24.  
  25. go tool commands that are wrapped:
  26. "+status" package selection may be used with them
  27. fmt,build,install,clean,test,vet,generate,tool
  28.  
  29. Status Types
  30.  
  31. +local (l) packages in your project
  32. +external (e) referenced packages in GOPATH but not in current project
  33. +vendor (v) packages in the vendor folder
  34. +std (s) packages in the standard library
  35.  
  36. +excluded (x) external packages explicitly excluded from vendoring
  37. +unused (u) packages in the vendor folder,but unused
  38. +missing (m) referenced packages but not found
  39.  
  40. +program (p) package is a main package
  41.  
  42. +outside +external +missing
  43. +all +all packages
  44.  
  45. Status can be referenced by their initial letters.
  46.  
  47. Package specifier
  48. <path>[::<origin>][{/...|/^}][@[<version-spec>]]
  49.  
  50. Ignoring files with build tags,or excluding packages from being vendored:
  51. The "vendor.json" file contains a string field named "ignore".
  52. It may contain a space separated list of build tags to ignore when
  53. listing and copying files.
  54. This list may also contain package prefixes (containing a "/",possibly
  55. as last character) to exclude when copying files in the vendor folder.
  56. If "foo/" appears in this field,then package "foo" and all its sub-packages
  57. ("foo/bar",…) will be excluded (but package "bar/foo" will not).
  58. By default the init command adds the "test" tag to the ignore list.
  59.  
  60. If using go1.5,ensure GO15VENDOREXPERIMENT=1 is set.

OK,结束,可以用git将vendor提交到代码库了。

本文参考:https://www.tuicool.com/articles/NjMzIbJ

使用godep管理Golang项目依赖

个人微信公众号:

作者:jiankunking 出处:http://blog.csdn.net/jiankunking

猜你在找的Go相关文章