Go

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.