Skip to content

Instantly share code, notes, and snippets.

@blockloop
Last active Oct 13, 2021
Embed
What would you like to do?
Automatically use the correct go version for your project with direnv + goenv
#!/bin/bash
#
# see: https://direnv.net/
# see: https://github.com/syndbg/goenv
#
# Place this in your go project root as .envrc
GOMOD_VERSION=$(grep 'go 1\.' go.mod | cut -d' ' -f2)
if [[ $GOMOD_VERSION =~ ^1\.[0-9]+$ ]]; then
GOMOD_VERSION="${GOMOD_VERSION}.0"
fi
if ! goenv versions | grep -q $GOENV_VERSION 2> /dev/null; then
goenv install $GOENV_VERSION
fi
export GOENV_VERSION=$GOMOD_VERSION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment