Golang-and-package-version-managment

Source: Internet
Author: User
Tags install go
This is a creation in Article, where the information may have evolved or changed.

Reference articles

After the study of Golang Golang in the version management, package management mechanism has not been very good pondering, accidentally think or feel it is necessary to summarize, package management use simple, nothing is, install uninstall ,, list etc., but in the project package management if inappropriate, It can cause a lot of unnecessary trouble.

Gvm

GVM is Golang version management program, why need such a version of management, because Golang is still in high-speed development, the release of frequent, upgrade iterations may not be completely compatible with the previous generation, so this tool came into being, like Ruby has corresponding rvm , node has corresponding nvm Are for easy switching of different versions.

Install

bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)

After installation, verify that the installation is successful

gvm version

Output

Go Version Manager v1.0.22 installed at /Users/liujb/.gvm

Supported commands

% gvmUsage: gvm [command]Description:  GVM is the Go Version ManagerCommands:  version    - print the gvm version number  get        - gets the latest code (for debugging)  use        - select a go version to use  diff       - view changes to Go root  implode    - completely remove gvm  install    - install go versions  uninstall  - uninstall go versions  cross      - install go cross compilers  linkthis   - link this directory into GOPATH  list       - list installed go versions  listall    - list available versions  alias      - manage go version aliases  pkgset     - manage go packages sets  pkgenv     - edit the environment for a package set

Common commands

    1. gvm listallView all Golang versions
    2. gvm install go1.4.2Install version 1.4.2
    3. gvm use go1.4.2With the go1.4.2 version, it GOPATH becomes the same as the /Users/liujb/.gvm/pkgsets/go1.4.2/global Gopath used by each version of Golang, so that the version compatibility issues between different Golang packages can be resolved.

gvp/gpm

Install

brew install gvpbrew install gpm

Use

These two packages are generally used in pairs, where the gvp command uses the primary settings GOPATH for the current directory, for example

source gvpecho $GOPATH    # 输出/Users/liujb/.godeps:/Users/liujb

The main gpm install two commands are the Godeps most important to install the package specified in the file by the command

$ gpm get         # Parses the Godeps file, gets dependencies and sets them                  # to the appropriate version but does not install them.$ gpm install     # Parses the Godeps file, installs dependencies and sets

And Godeps the files are similar

github.com/nu7hatch/gotrail               v0.0.2github.com/replicon/fast-archiver         v1.02launchpad.net/gocheck                     r2013.03.03   # Bazaar repositories are supportedcode.google.com/p/go.example/hello/...    ae081cd1d6cc  # And so are Mercurial ones

By the gpm install time the file is parsed and Godeps then the specified package and version are installed in the file, and installed in .godeps the directorysrc/bin/pkg

Godep

Install

go get github.com/tools/godep或者brew install godep

Use

Reference 1 Reference 2

At the root of the project, execute two commands, where the packages that need to be installed need go get to be downloaded to the $GOPATH bottom, and the other project needs to be under version management git hg .

godep savegodep restore

Godeps.json file format is as follows

{    "ImportPath": "github.com/kr/hk",    "GoVersion": "go1.1.2",    "Deps": [        {            "ImportPath": "code.google.com/p/go-netrc/netrc",            "Rev": "28676070ab99"        },        {            "ImportPath": "github.com/kr/binarydist",            "Rev": "3380ade90f8b0dfa3e363fd7d7e941fa857d0d13"        }    ]}

Gom

Install

go get github.com/mattn/gom

Use

Create Gomfiles

gom 'github.com/mattn/go-runewidth', :tag => 'go1'gom 'github.com/mattn/go-scan', :commit => 'ecb144fb1f2848a24ebfdadf8e64380406d87206'gom 'github.com/daviddengcn/go-colortext'gom 'github.com/mattn/go-ole', :goos => 'windows'# Execute only in the "test" environment.group :test do    gom 'github.com/mattn/go-sqlite3'end# Execute only for the "custom_group" group.group :custom_group do    gom 'github.com/golang/lint/golint'end

Perform

gom install

The directory is then created under the project _vendor .

% tree -L 4├── Gomfile└── _vendor    └── src        └── github.com            ├── daviddengcn            └── mattn5 directories, 1 file

Personal Summary

    1. gvmPlainly is golang the version management that parking management not half-gross money relationship
    2. gvp/gpmThis companion tool can be set to the current directory GOPATH , and also according to the Godeps file description, install the specified package to GVP the specified path.
    3. godepTo put it bluntly, the package will be installed through the go get JSON file Godeps.json saved to the directory under the project Godeps/_workspace , and then compile the time export GOPATH='Project/Godeps/_workspace':$GOPATH .
    4. gomWith npm the closest, just need a package description file, and then install to the specified location, the rest do not have to do, of course, don't forget to specifyGOPATH

The management mechanism of the package in Golang about so much, there are problems to communicate together. Reference to the source can be noted.

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.