Skip to content

Commit f3a8372

Browse files
committed
fix: 更新gostun版本以及增加提取错误的容错机制
1 parent a4ea7e0 commit f3a8372

12 files changed

Lines changed: 55 additions & 31 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ jobs:
77
test:
88
strategy:
99
matrix:
10-
go: ['1.22.x']
10+
go: ['stable']
1111
os: [ubuntu-latest]
1212
runs-on: ${{ matrix.os }}
1313
steps:
1414
- name: Checkout
15-
uses: actions/checkout@v2
15+
uses: actions/checkout@v4
1616

1717
- name: Setup Go
18-
uses: actions/setup-go@v2
18+
uses: actions/setup-go@v4
1919
with:
2020
go-version: ${{ matrix.go }}
2121

@@ -27,7 +27,7 @@ jobs:
2727
run: |
2828
git config --global user.name 'github-actions'
2929
git config --global user.email 'github-actions@github.com'
30-
TAG="v0.0.16-$(date +'%Y%m%d%H%M%S')"
30+
TAG="v0.0.17-$(date +'%Y%m%d%H%M%S')"
3131
git tag $TAG
3232
git push origin $TAG
3333
echo "TAG=$TAG" >> $GITHUB_ENV

.github/workflows/main.yaml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- name: Checkout code
18-
uses: actions/checkout@v3
18+
uses: actions/checkout@v4
1919

2020
- name: Set up Go
21-
uses: actions/setup-go@v3
21+
uses: actions/setup-go@v4
2222
with:
2323
go-version: 'stable'
2424

@@ -43,19 +43,23 @@ jobs:
4343
needs: build
4444
steps:
4545
- name: Checkout code
46-
uses: actions/checkout@v3
46+
uses: actions/checkout@v4
4747

4848
- name: Set up Go
49-
uses: actions/setup-go@v3
49+
uses: actions/setup-go@v4
5050
with:
5151
go-version: 'stable'
5252

5353
- name: Build and Release
5454
run: |
5555
mkdir -p bin
5656
cd cmd
57-
CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build \
58-
-o ../bin/basics-${{ matrix.goos }}-${{ matrix.goarch }} \
57+
GOARM_SUFFIX=""
58+
if [ -n "${{ matrix.goarm }}" ]; then GOARM_SUFFIX="-${{ matrix.goarm }}"; fi
59+
EXT=""
60+
if [ "${{ matrix.goos }}" = "windows" ]; then EXT=".exe"; fi
61+
CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} GOARM=${{ matrix.goarm }} go build \
62+
-o ../bin/basics-${{ matrix.goos }}-${{ matrix.goarch }}${GOARM_SUFFIX}${EXT} \
5963
-v \
6064
-ldflags="-extldflags=-static -s -w" \
6165
-trimpath \
@@ -74,6 +78,7 @@ jobs:
7478
done
7579
7680
strategy:
81+
fail-fast: false
7782
matrix:
7883
goos: [windows, freebsd, linux, darwin]
7984
goarch: [amd64, 386]

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/json-iterator/go v1.1.12
99
github.com/libp2p/go-nat v0.2.0
1010
github.com/oneclickvirt/defaultset v0.0.2-20240624082446
11-
github.com/oneclickvirt/gostun v0.0.5-20250727155022
11+
github.com/oneclickvirt/gostun v0.0.6-20260509043509
1212
github.com/shirou/gopsutil/v4 v4.25.6
1313
github.com/yusufpapurcu/wmi v1.2.4
1414
golang.org/x/sys v0.33.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
6060
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
6161
github.com/oneclickvirt/defaultset v0.0.2-20240624082446 h1:5Pg3mK/u/vQvSz7anu0nxzrNdELi/AcDAU1mMsmPzyc=
6262
github.com/oneclickvirt/defaultset v0.0.2-20240624082446/go.mod h1:e9Jt4tf2sbemCtc84/XgKcHy9EZ2jkc5x2sW1NiJS+E=
63-
github.com/oneclickvirt/gostun v0.0.5-20250727155022 h1:/e3gSUrOp1tg/1NTRx+P8B51OGcP26Q6//5EoSIjOvk=
64-
github.com/oneclickvirt/gostun v0.0.5-20250727155022/go.mod h1:pfp7MFZJK9n/KTLAVqqFcCAns4xqMykmjI+1UeF/vdE=
63+
github.com/oneclickvirt/gostun v0.0.6-20260509043509 h1:VoxIzEVQHsesHdNffA1Bv1H62nV9LM9kzbH32cE6K4U=
64+
github.com/oneclickvirt/gostun v0.0.6-20260509043509/go.mod h1:pfp7MFZJK9n/KTLAVqqFcCAns4xqMykmjI+1UeF/vdE=
6565
github.com/pion/dtls/v2 v2.2.7 h1:cSUBsETxepsCSFSxC3mc/aDo14qQLMSL+O6IjG28yV8=
6666
github.com/pion/dtls/v2 v2.2.7/go.mod h1:8WiMkebSHFD0T+dIU+UeBaoV7kDhOW5oDCzZ7WZ/F9s=
6767
github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY=

model/model.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package model
22

3-
const BasicsVersion = "v0.0.16"
3+
const BasicsVersion = "v0.0.17"
44

55
var EnableLoger bool
66

system/cpu.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,16 @@ func updateSystemLoad(ret *model.SystemInfo) {
224224
out, err := exec.Command("w").Output()
225225
if err == nil {
226226
loadFields := strings.Fields(string(out))
227-
load = strings.Join(loadFields[len(loadFields)-3:], " ")
227+
if len(loadFields) >= 3 {
228+
load = strings.Join(loadFields[len(loadFields)-3:], " ")
229+
}
228230
} else {
229231
out, err = exec.Command("uptime").Output()
230232
if err == nil {
231233
fields := strings.Fields(string(out))
232-
load = strings.Join(fields[len(fields)-3:], " ")
234+
if len(fields) >= 3 {
235+
load = strings.Join(fields[len(fields)-3:], " ")
236+
}
233237
}
234238
}
235239
if load != "" {
@@ -619,13 +623,22 @@ func getDarwinCpuInfo(ret *model.SystemInfo) (*model.SystemInfo, error) {
619623
if len(model.MacOSInfo) > 0 {
620624
for _, line := range model.MacOSInfo {
621625
if strings.Contains(line, "Chip") && ret.CpuModel == "" {
622-
ret.CpuModel = strings.TrimSpace(strings.Split(line, ":")[1])
626+
parts := strings.SplitN(line, ":", 2)
627+
if len(parts) == 2 {
628+
ret.CpuModel = strings.TrimSpace(parts[1])
629+
}
623630
}
624631
if strings.Contains(line, "Total Number of Cores") && ret.CpuCores == "" {
625-
ret.CpuCores = strings.TrimSpace(strings.Split(line, ":")[1])
632+
parts := strings.SplitN(line, ":", 2)
633+
if len(parts) == 2 {
634+
ret.CpuCores = strings.TrimSpace(parts[1])
635+
}
626636
}
627637
if strings.Contains(line, "Memory") && ret.MemoryTotal == "" {
628-
ret.MemoryTotal = strings.TrimSpace(strings.Split(line, ":")[1])
638+
parts := strings.SplitN(line, ":", 2)
639+
if len(parts) == 2 {
640+
ret.MemoryTotal = strings.TrimSpace(parts[1])
641+
}
629642
}
630643
}
631644
}
@@ -664,7 +677,10 @@ func updateSysctlCpuInfo(ret *model.SystemInfo, sysctlPath string) {
664677
if ret.CpuCache == "" {
665678
ccache, err := getSysctlValue(sysctlPath, "hw.cacheconfig")
666679
if err == nil && !strings.Contains(ccache, "cannot") {
667-
ret.CpuCache = strings.TrimSpace(strings.Split(ccache, ":")[1])
680+
parts := strings.Split(ccache, ":")
681+
if len(parts) > 1 {
682+
ret.CpuCache = strings.TrimSpace(parts[1])
683+
}
668684
}
669685
}
670686
}

system/disk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func deduplicatePhysicalDisks(diskInfos []DiskSingelInfo, currentDiskInfo *DiskS
119119
}
120120
}
121121
}
122-
if largest.BootPath != currentDiskInfo.BootPath || largest.MountPath != currentDiskInfo.MountPath {
122+
if currentDiskInfo == nil || largest.BootPath != currentDiskInfo.BootPath || largest.MountPath != currentDiskInfo.MountPath {
123123
result = append(result, largest)
124124
} else if !hasCurrent {
125125
result = append(result, largest)

system/load.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ func getLoadFromProc() (float64, float64, float64, error) {
2020
scanner := bufio.NewScanner(file)
2121
for scanner.Scan() {
2222
fields := strings.Fields(scanner.Text())
23+
if len(fields) < 3 {
24+
break
25+
}
2326
// 解析负载信息并转换为 float64 类型
2427
load1, _ := strconv.ParseFloat(fields[0], 64)
2528
load5, _ := strconv.ParseFloat(fields[1], 64)

system/utils/utils_darwin.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ func GetLoad1() float64 {
2626

2727
// GetTCPAccelerateStatus 查询TCP控制算法
2828
func GetTCPAccelerateStatus() string {
29-
cmd := exec.Command("sysctl", "-n", "net.ipv4.tcp_congestion_control")
29+
cmd := exec.Command("sysctl", "-n", "net.inet.tcp.cc_algorithm")
3030
var out bytes.Buffer
3131
cmd.Stdout = &out
3232
err := cmd.Run()
3333
if err != nil {
3434
return ""
3535
} else {
36-
return out.String()
36+
return strings.TrimSpace(out.String())
3737
}
3838
}
3939

@@ -56,7 +56,7 @@ func parseTimeZone(output string) string {
5656
// GetTimeZone 获取当前时区
5757
func GetTimeZone() string {
5858
var CurrentTimeZone string
59-
output, err := exec.Command("timedatectl", "|", "grep", "Time zone").Output()
59+
output, err := exec.Command("timedatectl").Output()
6060
if err == nil && strings.Contains(string(output), "Time zone") {
6161
timeZone := parseTimeZone(string(output))
6262
CurrentTimeZone = timeZone

system/utils/utils_freebsd.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ func GetLoad1() float64 {
2626

2727
// GetTCPAccelerateStatus 查询TCP控制算法
2828
func GetTCPAccelerateStatus() string {
29-
cmd := exec.Command("sysctl", "-n", "net.ipv4.tcp_congestion_control")
29+
cmd := exec.Command("sysctl", "-n", "net.inet.tcp.cc_algorithm")
3030
var out bytes.Buffer
3131
cmd.Stdout = &out
3232
err := cmd.Run()
3333
if err != nil {
3434
return ""
3535
} else {
36-
return out.String()
36+
return strings.TrimSpace(out.String())
3737
}
3838
}
3939

@@ -56,7 +56,7 @@ func parseTimeZone(output string) string {
5656
// GetTimeZone 获取当前时区
5757
func GetTimeZone() string {
5858
var CurrentTimeZone string
59-
output, err := exec.Command("timedatectl", "|", "grep", "Time zone").Output()
59+
output, err := exec.Command("timedatectl").Output()
6060
if err == nil && strings.Contains(string(output), "Time zone") {
6161
timeZone := parseTimeZone(string(output))
6262
CurrentTimeZone = timeZone

0 commit comments

Comments
 (0)