Skip to content

Instantly share code, notes, and snippets.

@ball6847
Last active February 3, 2018 20:59
Show Gist options
  • Select an option

  • Save ball6847/b526d4a70fe0853c06215abad95e5f2b to your computer and use it in GitHub Desktop.

Select an option

Save ball6847/b526d4a70fe0853c06215abad95e5f2b to your computer and use it in GitHub Desktop.
setup go workspace separated from $GOROOT using direnv, make it work nicely with gvm
#!/bin/bash -e
# assuming you've already installed GO and direnv
# and your desired workspace is at $HOME/go-workspace
# first, create workspace skeleton and go to workspace
mkdir -p ~/workspace/{bin,src,pkg}
cd ~/workspace/
# create .envrc with predefined layout (direnv built-in layout)
echo 'layout go' > .envrc
# trust this .envrc (required for first run)
dirnev allow
# and then, anytime you enter your workspace or its child directory
# direnv will automatically load workspace path into environment variable
# start working on a package
# let's try https://github.com/OscarYuen/go-graphql-starter
cd src/
git clone git@github.com:OscarYuen/go-graphql-starter.git github.com/OscarYuen/go-graphql-starter
cd $_
# it works pretty well. ;)
dep ensure
@ball6847
Copy link
Copy Markdown
Author

ball6847 commented Feb 3, 2018

This also works

mkdir -p ~/workspace/{bin,src,pkg}
cd ~/workspace/

Then put this into your ~/.zshrc

# activate gvm
[[ -s "$HOME/.gvm/scripts/gvm" ]] && source "$HOME/.gvm/scripts/gvm"

# modify $GOPATH
export GOPATH="$GOPATH:$HOME/workspace"
export PATH="$HOME/workspace/bin:$PATH"

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