Skip to content

Instantly share code, notes, and snippets.

@devinceble
Last active March 14, 2018 17:19
Show Gist options
  • Save devinceble/9181726 to your computer and use it in GitHub Desktop.
Save devinceble/9181726 to your computer and use it in GitHub Desktop.
Starting My Golang Project Adding To Path and Exporting $GOPATH
#!/usr/bin/env bash
function goproject {
export GOPATH=$(pwd)
add_to_path "$GOPATH/bin"
alias gocd="cd $GOPATH"
if [ -f goconf ]
then
lines=($(cat goconf))
cd ${lines[0]}
export GOPRJ=$(pwd)
alias goprj="cd $GOPRJ"
fi
}
function add_to_path ()
{
if [[ "$PATH" =~ (^|:)"${1}"(:|$) ]]
then
echo "Duplicate Path"
return 0
fi
export PATH=${1}:$PATH
}
$ gocd // GOTO $GOPATH
$ goprj // GOTO Main Source Project PATH $GOPRJ

###Download .goproject on your $HOME directory wget https://gist.githubusercontent.com/devinceble/9181726/raw/f77e75e61b3b27694774fbc992104c0fe488cff1/.goproject

###Add line at the end of your .bashrc or .bash_profile source .goproject

###Don't forget to source .bashrc or .bash_profile or just reload terminal :-)

###Create a goconf file inside your $GOPATH $ touch goconf $ echo src/code.google.com/p/odbc > goconf //Replace with your Main Source Path

###Now you can use goproject command on your $GOPATH $ goproject //it will automatically export $(pwd) as $GOPATH, append $GOPATH/bin on $PATH and goto your Main Source Path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment