Gopkg: A convenient way to manage your go package

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

In the process of using go, we sometimes introduce some third-party libraries to use, and the usual way is to use `go get ', but this way has a very serious problem, if the third-party library updates the relevant interface, it is likely that you will not be able to use, so we set a good package management mechanism.

Thoughts on the best practice of go language in the production environment I introduced the SoundCloud Company's practice, directly check down the code of the third library, put it in the vendor directory of your project, or use GODEP.

But now, I have found a better package management style gopkg. It allows the Go tool to check the specified repository by agreeing to use a URL with a version number, although it now supports GitHub's go repositories, but I think it's strong enough.

A very simple example, we get the YAML package for go in the following way

Go get gopkg.in/yaml.v1

In fact, the corresponding address of the YAML package is:

Https://github.com/go-yaml/yaml

YAML.V1 indicates that the version is V1, and on GitHub there is a corresponding V1 branch.

The URL format supported by gopkg is simple:

Gopkg.in/pkg.v3      →github.com/go-pkg/pkg (Branch/tag v3, v3. N, or v3. N.M) gopkg.in/user/pkg.v3→github.com/user/pkg   (Branch/tag v3, v3. N, or v3. N.M)

We use V. n the way to define a version, and then GitHub above the corresponding to establish a branch of the same name. Gopkg support `(vMAJOR[.MINOR[.PATCH]]) ' This type of version mode, if there are multiple major the same version, such as v1,v1.0.1,v1.1.2, then gopkg will choose the highest level of v1.1.2 use, such as the following version:

    • V1
    • v2.0
    • v2.0.3
    • v2.1.2
    • V3
    • v3.0

Then the gopkg corresponds to the choice of the following methods:

    • PKG.V1-V1
    • Pkg.v2-v2.1.2
    • Pkg.v3-v3.0

GOPKG does not recommend the use of V0, which is the 0 version number.

GOPKG also lists some suggestions for whether you need to upgrade the major version after updating your code, or if you do not need to upgrade the main version:

    • Delete or rename any of the exported interfaces, functions, variables, etc.
    • Add, delete, or rename a function to an interface
    • Add parameters to a function or interface
    • Change the parameters or return value types of a function or interface
    • Change the number of return values for a function or interface
    • Change the structure body

In the case of a situation, you do not need to upgrade the major version number:

    • Add an export interface, function or variable
    • Renamed the parameter name of the function or interface.
    • Change the structure body

As mentioned above, change the structure, for example, if I add a field to a struct, I may not need to upgrade the main version, but if you delete an export field from the struct, you must upgrade it. If you simply change the contents of a non-exported field in a struct, you do not need to upgrade.

For more detailed information, please see gopkg directly.

As you can see, Gopkg uses a very simple way for us to manage the release of Go pakcage conveniently. So I also according to gourd painting scoop, to my log package made a V1 version, you can directly `go get gopkg.in/siddontang/go-log.v1/log '.

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.