Also talk about the Go language code package distribution

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

The Go language currently (as of 1.0.2) does not yet support direct links. A file (here,. A file is not a traditional static shared library, but a product of Golang's non-main package build). In this way, the third-party library package for go or the Public code library package inside the organization can only be distributed as source.

Go provides a GET command to get code packages that others distribute. We can get the code on some well-known code hosting site through the Get command, or we can get the common code on the organization's internal version control server.

The managed sites supported by Go get include GitHub, Google Code, BitBucket, and Launchpad, where we can get the "special" syntax to take care of:

Go get Github.com/bmizerany/assert
Go get Bitbucket.org/bmizerany/assert
Go get Code.google.com/p/assert
Go get Launchpad.net/assert

Since Go has "built-in" the type of version control tool for GitHub, Google Code, and so on, we don't need to make any additional designations, just use the URL of the code (remove http://).

After the get is executed, the code is downloaded to the SRC directory under the first path in the GOPATH environment variable configuration. For example: Our gopath=/home/tonybai/goworkspace1:/home/tonybai/goworkspace2, after executing go get github.com/bmizerany/assert, we will be in the/ Home/tonybai/goworkspace1 See the Github.com directory, while the Assert package is local to the full path is/home/tonybai/goworkspace1/github.com/bmizerany/ Assert. This allows us to import "Github.com/bmizerany/assert" directly into the code to use Assert, the third-party package.

Within the organization we also have our own private public code base, a code base that may be used by multiple projects. Keeping a common library code in each project is obviously not conducive to subsequent versions of the upgrade maintenance, which requires each project to be unified from the same place to obtain or update the common library code. In this case we can also use go get command to do.

Assuming that subversion is used internally as a version control tool, the public library is set up in 10.10.12.13/svn0/share/golib. At this point we cannot simply get to the code through "Go get 10.10.12.13/svn0/share/golib", we need to tell get what version of the control tool we are using, and this information is passed by appending a suffix to the name of the library. Like what:

Go get "10.10.12.13/svn0/share/golib.svn"

This will cause the 10.10.12.13/SVN0/SHARE/GOLIB.SVN directory structure to appear under/home/tonybai/goworkspace1. We can import the corresponding package directly in the code, such as import "10.10.12.13/svn0/share/golib.svn/assert".

By understanding the features of the Get command, we can also determine how the distributed code package should be organized. From the above example we can see that we distribute the code package structure does not need to be very complex, directly in the library repository under the package directory can be, such as the above example, the library repository for Golib,assert is directly built in the following directory, but also the package name.

Go get automatically recognizes http_proxy environment variables, so go can also get external code packages through proxies.

Projects that use external code packages can update the code package version to the latest version with the Go Get-u URL.

, Bigwhite. All rights reserved.

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.