Skip to content

Instantly share code, notes, and snippets.

@dchest
Created April 8, 2011 18:00
Show Gist options
  • Save dchest/910389 to your computer and use it in GitHub Desktop.
Save dchest/910389 to your computer and use it in GitHub Desktop.
Switch between two different installations of Go
#!/bin/sh
#
# Switch between two different installations of Go:
#
# source goswitch dev
# ^ makes GOROOT ~/Sources/go
#
# source goswitch prod
# ^ makes GOROOT ~/go
#
# source goswitch
# ^ sets whatever the last version was
#
VERSION_FILE=$HOME/.goversion
function set_environment {
export GOOS=darwin
export GOARCH=amd64
export GOROOT=$1
export PATH=$1/bin:$PATH
echo "GOROOT is now $1"
}
function set_version {
case $1 in
dev )
GOPATH="$HOME/Sources/go"
;;
prod )
GOPATH="$HOME/go"
;;
* )
return 1
esac
set_environment "$GOPATH"
echo "** Switched to $1 version **"
echo "$1" > $VERSION_FILE
return 0
}
set_version $1
if [ $? -eq "1" ]; then
if [ -e $VERSION_FILE ]; then
set_version $(cat $VERSION_FILE)
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment