mirror of
https://gitee.com/samwaf/SamWaf.git
synced 2026-11-02 11:11:47 +08:00
Merge pull request #582 from samwafgo/fix_debian_runfailed
fix:debain run failed
This commit is contained in:
@@ -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
|
||||
|
||||
+6
-4
@@ -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:
|
||||
|
||||
+27
-6
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user