Defina o ambiente Golang antes de começar com o código go

###
#
# @usage `source set_env.sh`
# @desc Sets the environment for developers
# @install Put this file into the GO Workspace directory
#
# bash-$ ls workspace/go/
# - set_env.sh*
# - bin/
# - src/
# - tmp/
# - pkg/
#
###

O código :

#!/bin/bash

#Get the script's own directory instead of where it's being called from
DIR
="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Set PATH
if [[ "$PATH" != ?(*:)"$DIR/bin"?(:*) ]]; then
export PATH=$PATH:$DIR/bin
fi

# Set GOPATH - used by GO
if [[ -z "$GOPATH" ]]; then
export GOPATH=$DIR
fi