#!/usr/bin/env bash

# Using the snap version of go if available. Or wherever Debian hides newer
# Go

set -x

export LC_ALL=C.utf8
# TODO: this should be automatic
export GOVERSION=1.21

# Check if go is installed through snap
if [ -f /home/linuxbrew/.linuxbrew/bin/go ]; then
	/home/linuxbrew/.linuxbrew/bin/go "$@"

elif [ -f /var/lib/snapd/snap/bin/go ]; then
	snap run go "$@"

# Or if Debian hides it somewhere nice.
elif [ -f /usr/lib/go-$GOVERSION/bin/go ]; then
	/usr/lib/go-$GOVERSION/bin/go "$@"

# Fallback to system default version
else
	/usr/bin/go "$@"
fi

set +x
