set proxy

This commit is contained in:
qing committed 2026-07-25 01:33:13 +08:00
1 parent 202f2804b2
commit 7df0d51879
2 files changed
+37 -5

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
#!/bin/bash
# 设置 Go 模块代理为国内镜像,加速依赖下载
# 仅当用户未显式设置 GOPROXY 或仍为默认值时修改
set -e
if ! command -v go >/dev/null 2>&1; then
echo "[skip] 未找到 go,跳过 GOPROXY 设置"
exit 0
fi
CURRENT=$(go env GOPROXY)
# 已显式设置为非默认值(如用户自配 corporate proxy),尊重用户配置不覆盖
if [ "$CURRENT" != "https://proxy.golang.org,direct" ] && [ -n "$CURRENT" ]; then
echo "[skip] GOPROXY 已配置为: $CURRENT"
exit 0
fi
# 优先用环境变量 GOPROXY(临时设置),否则写入 go env 持久化
if [ -n "${GOPROXY:-}" ]; then
echo "[ok] 使用环境变量 GOPROXY=$GOPROXY"
exit 0
fi
echo "[setup] 永久设置 GOPROXY=https://goproxy.cn,direct"
go env -w GOPROXY=https://goproxy.cn,direct
go env -w GOSUMDB=sum.golang.google.cn
echo "[ok] 当前 GOPROXY=$(go env GOPROXY) GOSUMDB=$(go env GOSUMDB)"
+9 -5
View File
@@ -1,6 +1,6 @@
#!/bin/bash
# 构建 WAF 单二进制
set -e
set -euo pipefail
cd "$(dirname "$0")" || exit
if ! command -v go >/dev/null 2>&1; then
@@ -8,10 +8,14 @@ if ! command -v go >/dev/null 2>&1; then
exit 1
fi
echo "[1/2] 下载依赖"
go mod download
# 设置 GOPROXY 国内镜像(仅当未显式配置时)
bash "$(dirname "$0")/_goproxy.sh"
echo "[2/2] 编译"
CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" -o waf.bin .
echo "[1/2] 下载依赖(go mod download -x)"
time go mod download -x
echo "[2/2] 编译(go build -v)"
time CGO_ENABLED=0 go build -v -trimpath -ldflags "-s -w" -o waf.bin .
echo "完成: $(pwd)/waf.bin"
ls -lh waf.bin