~edwardloveall/dotfiles

1d3a9e7d6ea2aceb7a820b9adc19a265cc32ffb4 — Edward Loveall 9 months ago 4da2ec7
Set GOROOT to asdf install location

GOROOT it where the go language is installed. Multiple go installations (like multiple versions) should have different GOROOTs. This sets GOROOT to the asdf install directory.

I also run into a lot of documentation about GOPATH. Since go 1.11, GOPATH is [no longer needed](https://stackoverflow.com/a/53026674/638966). I think this is because go can now use the current directory by default.

## References

https://golangr.com/what-is-gopath/
https://golang.co/difference-between-gopath-and-goroot/
https://www.jetbrains.com/help/go/configuring-goroot-and-gopath.html
https://go.dev/doc/code
3 files changed, 15 insertions(+), 3 deletions(-)

M install.sh
A plugins/dot-set-go-env.sh
M zsh/dot-zshrc
M install.sh => install.sh +1 -1
@@ 1,3 1,3 @@
#!/bin/sh

stow --verbose --dotfiles --target="$HOME" zsh git configs vim
stow --verbose --dotfiles --target="$HOME" zsh git configs vim plugins

A plugins/dot-set-go-env.sh => plugins/dot-set-go-env.sh +13 -0
@@ 0,0 1,13 @@
# https://go.dev/doc/gopath_code
# https://github.com/kennyp/asdf-golang/pull/56

asdf_update_golang_env() {
  local go_root
  go_root="$(asdf where golang)"
  if [[ -n "${go_root}/go" ]]; then
    export GOROOT
    GOROOT="${go_root}/go"
  fi
}
autoload -U add-zsh-hook
add-zsh-hook precmd asdf_update_golang_env

M zsh/dot-zshrc => zsh/dot-zshrc +1 -2
@@ 104,8 104,7 @@ export RIPGREP_CONFIG_PATH=~/.ripgreprc
export PKG_CONFIG_PATH="/opt/homebrew/lib/pkgconfig:$PKG_CONFIG_PATH"

# go
# https://go.dev/doc/gopath_code
export GOPATH="$HOME/Code/go"
source ~/.set-go-env.sh

### Local overrides ###