Go

Using Go Dep to Manage Dependencies

dep is a dependency management tool for golang. If you have done any software development before, dep is similar to npm, pod or pip. In simple words, it is a package manager to manage your project’s third party libraries. How to install it There’s a few ways to install dep. Personally I prefer to install it with Homebrew $~ brew install dep Initializing a project with dep To initialize it in your go project, go to your project directory and run the following

Go Examples and Benchmarks

I learned about Go examples and benchmarks today. They are parts of Go default package testing. Examples Go Examples are executed just like tests They are compiled and optionally executed as part of unit tests It resides in the package *_test.go files Structure func ExampleRepeat() { repeated := Repeated("x", 5) fmt.Println(repeated) // output: xxxxx } Rules Function name must be prefix with Example It must have // output: result How to Use to run the test with example, use: go test -v Sample Execution $ go test -v === RUN TestRepeat --- PASS: TestRepeat (0.

Setting Up $GOPATH

GOPATH specifies the location of your go workspace. By default this will be $HOME/go. You should set your $GOPATH in .zshrc or .bash_profile to be used later in scripts or shell. Add the followings into your .bash_profile: export GOPATH=$HOME/go export PATH=$PATH:$GOPATH/bin Reload your shell and done. To confirm that it’s working, enter $GOPATH in your shell and it should take you to the go workspace directory.