go语言版本控制

在使用Golang过程中,我们发现Golang程序缺少依赖库版本功能是一个非常令人头大的问题:某些依赖在某个commit之后发生了API变更之后,如果不修改代码很难兼容,然而开发者之间很有可能因为参与的时间不同,导致执行 go get 命令获取的版本不同,而导致在不同电脑上出现编译不通过问题。同时,在多个程序中,如果使用的commit版本不同,也可能会导致程序编译过程中出现不同的问题。

在Golang1.5之后,Go提供了 GO15VENDOREXPERIMENT 环境变量,用于将go build时的应用路径搜索调整成为 当前项目目录/vendor 目录方式。Golang在1.5版本引入了实验性的vendoring标记GO15VENDOREXPERIMENT,并且从1.6版本起使vendoring机制成为默认行为,不再需要额外配置

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

首先有一个名为 test 的项目,

govendor init     #执行一下命令就可以生成vendor文件夹

govendor add +external    #执行命令将当前应用必须的文件包含进来

下面是govendor详细命令
[root@k8s-node1 fabric-sdk-service-pig]# govendor --help
govendor (v1.0.9): record dependencies and copy into vendor folder
    -govendor-licenses    Show govendor's licenses.
    -version              Show govendor version
    -cpuprofile 'file'    Writes a CPU profile to 'file' for debugging.
    -memprofile 'file'    Writes a heap profile to 'file' for debugging.

Sub-Commands

    init     Create the "vendor" folder and the "vendor.json" file.
    list     List and filter existing dependencies and packages.
    add      Add packages from $GOPATH.
    update   Update packages from $GOPATH.
    remove   Remove packages from the vendor folder.
    status   Lists any packages missing, out-of-date, or modified locally.
    fetch    Add new or update vendor folder packages from remote repository.
    sync     Pull packages into vendor folder from remote repository with revisions
                   from vendor.json file.
    migrate  Move packages from a legacy tool to the vendor folder with metadata.
    get      Like "go get" but copies dependencies into a "vendor" folder.
    license  List discovered licenses for the given status or import paths.
    shell    Run a "shell" to make multiple sub-commands more efficient for large
                 projects.

    go tool commands that are wrapped:
      "+status" package selection may be used with them
    fmt, build, install, clean, test, vet, generate, tool

Status Types

    +local    (l) packages in your project
    +external (e) referenced packages in GOPATH but not in current project
    +vendor   (v) packages in the vendor folder
    +std      (s) packages in the standard library

    +excluded (x) external packages explicitly excluded from vendoring
    +unused   (u) packages in the vendor folder, but unused
    +missing  (m) referenced packages but not found

    +program  (p) package is a main package

    +outside  +external +missing
    +all      +all packages

    Status can be referenced by their initial letters.

Package specifier
    <path>[::<origin>][{/...|/^}][@[<version-spec>]]

Ignoring files with build tags, or excluding packages from being vendored:
    The "vendor.json" file contains a string field named "ignore".
    It may contain a space separated list of build tags to ignore when
    listing and copying files.
    This list may also contain package prefixes (containing a "/", possibly
    as last character) to exclude when copying files in the vendor folder.
    If "foo/" appears in this field, then package "foo" and all its sub-packages
    ("foo/bar", …) will be excluded (but package "bar/foo" will not).
    By default the init command adds the "test" tag to the ignore list.

If using go1.5, ensure GO15VENDOREXPERIMENT=1 is set.







展开阅读全文

没有更多推荐了,返回首页