stefanmaric/g

[question] g compared to goenv

omares opened this issue · 2 comments

Hey there,

you are listing various g alternatives but you are missing goenv. Do you mind adding it?

Best

Hey @omares, I actually didn't know about it.

It looked to me like a good alternative and gave it a try. I'm going to add the key points to the readme but going to leave an extended comparison here for future reference.

So the approaches are different, g relies on fixed values for GOPATH, GOROOT and PATH and simply copies over the files for the activated version into the fixed GOROOT dir, g always uses a "global" version (not actually, but more on that later).

goenv works by injecting several dirs into your PATH, shim files named as the various go commands are run instead of the real ones and those simply read a file (or env var) that holds the active go version and look for it inside the versions folder to run it, passing whatever arguments they got.

What I don't like about goenv:

  • You have to upgrade goenv before getting a new version of go since it keeps a hardcoded list of versions.
  • Adds a lot to your env and PATH.
  • Onboarding experience is not very smooth, besides manually cloning the repo (in case you don't have Mac or don't use homebrew) and editing init files, it was not clear to me that after installing a go version I had to activate it with goenv global <version>.
  • In general I feel it too complicated to me, less than others like gvm but still complicated.

One thing you might miss from goenv is go versions in a project basis, but it can be mocked using g. For example, in bash, if you want to have this functionality, you can simply add this alias to your init file:

go() {
  if [[ -f ".go-version" ]]; then
    local version=$(cat .go-version)
    if g run "$version" version > /dev/null; then
      g run "$version" "$@"
    else
      g install "$version" && g run "$version" "$@"
    fi
  else
    command go "$@"
  fi
}

g manages a global go version only, but g run allows you to run versions in a command basis.

Right now, g run simply fails if you indicate a version that's not installed yet, thus the check on that snippet. I might consider to change its behavior to simply install the requested version if not already.

I might also consider having the install script to optionally setup this alias in known shells.

Overall, I think g is way simpler than goenv and provides almost the same feature set with an easier kickoff, which is the main reason for g to exist.

Going to close this issue but feel free to continue the thread.