From 117a94f4a775a1b256e1a365a7c97ce12d6a238c Mon Sep 17 00:00:00 2001 From: samwaf Date: Fri, 5 Dec 2025 17:15:18 +0800 Subject: [PATCH] fix:debain run failed #563 --- .github/workflows/goreleaser.yml | 2 +- .goreleaser.yaml | 10 ++++++---- utils/common.go | 33 ++++++++++++++++++++++++++------ 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index 1af19fd..822a470 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -31,7 +31,7 @@ jobs: - name: Install dependencies for cross-compilation run: | sudo apt-get update - sudo apt-get install -y gcc-mingw-w64-x86-64 gcc-mingw-w64-i686 gcc-aarch64-linux-gnu g++-aarch64-linux-gnu build-essential + sudo apt-get install -y gcc-mingw-w64-x86-64 gcc-mingw-w64-i686 gcc-aarch64-linux-gnu g++-aarch64-linux-gnu build-essential musl-tools - name: Run GoReleaser (Linux/Windows only) uses: goreleaser/goreleaser-action@v4 diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 6bac695..bc8641a 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -26,9 +26,10 @@ builds: binary: "SamWafLinux64" env: - CGO_ENABLED=1 - - CC=x86_64-linux-gnu-gcc - - CXX=x86_64-linux-gnu-g++ + - CC=x86_64-linux-musl-gcc + - CXX=x86_64-linux-musl-g++ - CGO_CFLAGS=-Wno-unused-variable + - GOAMD64=v1 goos: - linux goarch: @@ -82,9 +83,10 @@ builds: binary: "SamWafLinux64-DEBUG-SYMBOLS" env: - CGO_ENABLED=1 - - CC=x86_64-linux-gnu-gcc - - CXX=x86_64-linux-gnu-g++ + - CC=x86_64-linux-musl-gcc + - CXX=x86_64-linux-musl-g++ - CGO_CFLAGS=-Wno-unused-variable + - GOAMD64=v1 goos: - linux goarch: diff --git a/utils/common.go b/utils/common.go index 130af61..a5c6c29 100644 --- a/utils/common.go +++ b/utils/common.go @@ -7,8 +7,6 @@ import ( "crypto/tls" "errors" "fmt" - "github.com/lionsoul2014/ip2region/binding/golang/xdb" - "github.com/oschwald/geoip2-golang" "io/ioutil" "net" "net/http" @@ -18,17 +16,40 @@ import ( "strconv" "strings" "time" + + "github.com/lionsoul2014/ip2region/binding/golang/xdb" + "github.com/oschwald/geoip2-golang" ) func GetExternalIp() string { - resp, err := http.Get("http://myexternalip.com/raw") + // 创建带超时的HTTP客户端,避免DNS解析问题 + client := &http.Client{ + Timeout: 10 * time.Second, + Transport: &http.Transport{ + DialContext: (&net.Dialer{ + Timeout: 5 * time.Second, + KeepAlive: 5 * time.Second, + }).DialContext, + TLSHandshakeTimeout: 5 * time.Second, + ResponseHeaderTimeout: 5 * time.Second, + ExpectContinueTimeout: 1 * time.Second, + }, + } + + resp, err := client.Get("http://myexternalip.com/raw") if err != nil { + zlog.Debug("GetExternalIp failed: %v", err) return "" } defer resp.Body.Close() - //io.Copy(os.Stdout, resp.Body) - body, _ := ioutil.ReadAll(resp.Body) - clientIP := fmt.Sprintf("%s", string(body)) + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + zlog.Debug("ReadAll failed: %v", err) + return "" + } + + clientIP := strings.TrimSpace(string(body)) return clientIP }