accounts/scripts/init-go.sh
2026-01-24 22:42:40 +08:00

29 lines
596 B
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
set -euo pipefail
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/_common.sh"
if [ ! -f go.mod ]; then
echo ">>> go.mod not found, initializing module"
go mod init account
fi
go mod tidy
echo ">>> 检查 Go 环境"
if ! command -v go >/dev/null; then
echo "未安装 Go自动安装中..."
if [ "${OS:-}" = "Darwin" ]; then
brew install go@1.24
brew link --overwrite --force go@1.24
else
sudo apt-get update
sudo apt-get install -y golang
fi
fi
echo ">>> 配置 Go Proxy"
go env -w GOPROXY=https://proxy.golang.org,direct
go mod tidy