Updated the default packages command to use "go install" for versions 1.16+ (#67)

* Updated the default packages command to use "go install" for versions
greater than 1.16

* Cleaning up for linting, added condition to also check major version

* Update Version Parsing

Attempts to make shell check happy.

Co-authored-by: john.maguire <john.maguire@cbinsights.com>
Co-authored-by: Kenny Parnell <k.parnell@gmail.com>
This commit is contained in:
John Maguire 2022-02-09 14:18:21 -05:00 committed by GitHub
parent 4aed736821
commit 89ced07d86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,7 +20,7 @@ install_golang () {
fi
tar -C "$install_path" -xzf "${download_path}/archive.tar.gz"
if [ "1" = "$created_tmp" ]; then
rm -r "$download_path"
fi
@ -29,9 +29,11 @@ install_golang () {
install_default_go_pkgs() {
local go_path="$1/go/bin"
local default_go_pkgs="${ASDF_GOLANG_DEFAULT_PACKAGES_FILE:-${HOME}/.default-golang-pkgs}"
IFS=. read -r go_major_version go_minor_version <<<"${2}"
if [ ! -f "$default_go_pkgs" ]; then return; fi
while read -r line; do
name=$(echo "$line" | \
sed 's|\(.*\) //.*$|\1|' | \
@ -41,10 +43,19 @@ install_default_go_pkgs() {
if [ -z "$name" ]; then continue ; fi
echo -ne "\nInstalling \033[33m${name}\033[39m go pkg... " >&2
GOROOT="$ASDF_INSTALL_PATH/go" \
GOPATH="$ASDF_INSTALL_PATH/packages" \
PATH="$go_path:$PATH" \
go get -u "$name" > /dev/null && rc=$? || rc=$?
# if using go > 1.16 then use go install as the preferred donwload path
if [ "$go_major_version" -ge 2 ] || [ "${go_minor_version//[!0-9]*}" -ge 16 ]; then
GOROOT="$ASDF_INSTALL_PATH/go" \
GOPATH="$ASDF_INSTALL_PATH/packages" \
PATH="$go_path:$PATH" \
go install "$name" > /dev/null && rc=$? || rc=$?
else
GOROOT="$ASDF_INSTALL_PATH/go" \
GOPATH="$ASDF_INSTALL_PATH/packages" \
PATH="$go_path:$PATH" \
go get -u "$name" > /dev/null && rc=$? || rc=$?
fi
if [[ $rc -eq 0 ]]; then
msg "SUCCESS"
@ -55,4 +66,4 @@ install_default_go_pkgs() {
}
install_golang "$ASDF_INSTALL_VERSION" "${ASDF_DOWNLOAD_PATH:-}" "$ASDF_INSTALL_PATH"
install_default_go_pkgs "$ASDF_INSTALL_PATH"
install_default_go_pkgs "$ASDF_INSTALL_PATH" "$ASDF_INSTALL_VERSION"