티스토리 뷰

Technology/Golang

GB Tool for dependency

캡틴테크 2017. 5. 21. 16:46

Every language requires to make dependency for building and exists various tools. Golang is needed to make dependency for building with several files. It doesn't matter with a few files, but if you want to add up to 3rd library and maintain the source in git, you should check dependency. Let's you give an example to understand better. If you want to gorilla/mux package(https://github.com/gorilla/mux) from github, you will take it and install in your src folder of GOPATH. It's okay to build in your PC and upload your code into your git and give the information to your coworker like 'I made the library for http server!! you can use it~!' However your coworker is not able to build, actually he or she can build but faces some issue regarding 3rd library like gorilla/mux package. His or her host PC doesn't have gorilla/mux package in their GOPATH. In order to do better collaborating, we'd better to provide 3rd party package together in own git. If somebody takes your code from git, he can build successfully. But there is a few way to make dependency with tools. I would like introduce one of tools regarding build dependency. 

# Management Dependency.

godep, vendor, glide, gb, ..., If you try to search, you can find out these tools to management for dependency. I also saw godep in some of opensources. But I think it's little confused because of version. Normally, If someone used godep tool for dependency, they used to make workspace folde to include 3rd party library. But other case, they used to make vendor folder. What is the differentiation? If I need to understand clearly, I must search to know about the knowledge. 

godep : https://github.com/tools/godep

If you want to check briefly about godep, you can come over the git and install in you work environment. In case of me, I decided to use gb tool for dependency due to easiness.

gb : https://github.com/constabulary/gb

Once you visit to the git and install gb according to explanation.

go get github.com/constabulary/gb/...

Assuming, you have installed 'go' in your PC and set up network to connect to the git. 'go get' command will take the package from mentioned path.

$ gb

gb, a project based build tool for the Go programming language

Usage:

        gb vendor command [arguments]

The commands are:

        fetch       fetch a remote dependency

        update      update a local dependency

        list        lists dependencies, one per line

        delete      deletes a local dependency

        purge       purges all unreferenced dependencies

        restore     restore dependencies from the manifest

Use "gb vendor help [command]" for more information about a command.

Additional help topics:


Use "gb vendor help [topic]" for more information about that topic.

Did you get the result when you type as gb ?, If you install gb tool in your window PC, you have to type gb-vendor otherwise, you can see the result when you type ad gb.

# Let's add up to 3rd library in your project

Once, If you make the code like the below to use 3rd library.

package main
import "github.com/gorilla/mux"

func main() {
        router := mux.NewRouter()
}

If you got the package using 'go get' command, the package will be in your gopath. Now, you try to take the package in your project folder using gb tool.

gb vendor fetch github.com/gorilla/mux

If you type the command and press enter, gb takes the package in your project source folder and you can see manifest file what packages placed. 'vendor' folder is created and let's see the manifest file what it is in.

$ cat vendor/manifest { "version": 0, "dependencies": [ { "importpath": "github.com/gorilla/mux", "repository": "https://github.com/gorilla/mux", "revision": "599cba5e7b6137d46ddf58fb1765f5d928e69604", "branch": "master" }, ] }


If you want to build with your code and library you should type as 'gb build'

gb build

Otherwise you can remove, update, restore, purge libraries that you had added.

  • fetch : fetch a remote dependency
  • update : update a local dependency
  • list : lists dependencies, one per line
  • delete : deletes a local dependency
  • purge : purges all un-referenced dependencies
  • restore : restore dependencies from the manifest

So far I have been using gb tool when I make my project and satisfied well. In terms of collaboration, It's the good way but you can make optional way with '.gitignore'. Because 3rd library packages can be downloaded when it build. Anyway it's your choice. 


댓글