Go language Godep for packet management

First, why should package management

Go default third-party packages are placed in the src directory Gopath, and these packets are not the concept of a version number, this may be some problems.

For example: A colleague after the completion of the development process, this time may refer to a third-party packages, then before long, B colleagues to take over the project at this time if B colleagues go get command to get the package, and the upgraded version of the package, the package happens not compatible with the previous version, which will lead to compile errors and other issues. Or when the third-party maintenance package is deleted, then B students can not be downloaded to the package.

Can know from the above example, why the need for the dependency management package.

Tools go inside for packet dependency management there are several. godep is one of them.

 

Second, the installation godep

1. Installation: go get github.com/tools/godep

2. Verify that the installation was successful: in the shell type godep, should appear helpful information.

Usage: 

        godep the Command [arguments The] 

at The Commands are: 

    the Save List and the Dependencies INTO Godeps // Copy the Save command is mainly used to save the current dependency 
    go run the go tool with saved dependencies // Go program is mainly used to perform, the equivalent of in the original go command sets the floor, because it involves a package management 
    get download and install packages with specified dependencies // get command is mainly used to get the currently specified dependencies 
    path dependency Print GOPATH code for 
    Restore the Check OUT dependency versions listed in GOPATH // the dependent packages are downloaded to Gopath which 
    update update selected packages or the go version // update package dependent 
    diff Shows at the Current and the BETWEEN diff of Previously saved the SET of the dependencies 
    Version Version Show info

  

Third, demonstrates how to use godep

The following items using a third-party packages, then we can carry on using the package management godep

1. In the project root directory, execute godep save command, if successfully implemented, it will generate two folders and vendor Godeps

godep save saves the current package depends scanned all third party packages, and then placed in the source code directory vendor.

Saved GoDeps is dependent on third-party packages

Vendor save all rely on third-party packages

You can look Godep.json

{
    "ImportPath": "godepDemo/protobuf",
    "GoVersion": "go1.10",
    "GodepVersion": "v80",
    "Deps": [
        {
            "ImportPath": "github.com/golang/protobuf/proto",
            "Comment": "v1.3.2-1-g4c88cc3f",
            "Rev": "4c88cc3f1a34ffade77b79abc53335d1e511f25b"
        }
    ]
}

Deps this field which holds the current path dependencies, version number git commit. After the next time down code execution Go build Vendor will execute the code inside, so you no longer have to worry about inconsistencies code issues.

Note: When the referenced third-party packages to upgrade how to do, then the modified version submitted Godep.json inside the line.

 

Godep is how to achieve version management, refer to the following chart.

 

Summarize how to use godep

1. To ensure that the program can correctly compile

2. Run godep save command after the execution of the third party will all dependent packages scanned, and generating Godeps Vendor Catalog

3. Submit the above two folders to your code base, after the submission of the third-party code that we rely on fixed down.

4. If you need to update your version dependencies, then directly update the version number of third-party packages godep.json inside, and then perform a godep save, and finally submitted to our code base line.

For example: I can look commitId dependent protobuf of

 

And then update the version number inside look Godeps.json

Guess you like

Origin www.cnblogs.com/dcz2015/p/11428458.html