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.

On Jotting Down

I started reading Joel’s Joel on Software today and there’s this excerpt that I quite like .. if you know something, you need to publish it on the Web for others to learn from. Guessed that’s probably why I did this again. ¯\_(ツ)_/¯

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.