Skip to content

Commit 02dc41a

Browse files
committed
v0.0.1 - 初始化项目
1 parent 27f4b0d commit 02dc41a

730 files changed

Lines changed: 243642 additions & 1 deletion

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CI
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
test:
8+
strategy:
9+
matrix:
10+
go: [ '1.22.x' ]
11+
os: [ ubuntu-latest ]
12+
runs-on: ${{ matrix.os }}
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v2
16+
- name: Setup Go
17+
uses: actions/setup-go@v2
18+
with:
19+
go-version: ${{ matrix.go }}
20+
- name: Test
21+
run: go test ./... -coverprofile=coverage.txt
22+
- name: Create Tag
23+
if: success() # 仅在测试成功时运行
24+
run: |
25+
git config --global user.name 'github-actions'
26+
git config --global user.email 'github-actions@github.com'
27+
TAG="v0.0.1-$(date +'%Y%m%d%H%M%S')"
28+
git tag $TAG
29+
git push origin $TAG
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/main.yaml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
name: Build and Release
2+
3+
on:
4+
# push:
5+
# branches: [ main ]
6+
# pull_request:
7+
# branches: [ main ]
8+
# release:
9+
# types: [published]
10+
workflow_dispatch:
11+
12+
jobs:
13+
build:
14+
name: Build and Test
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v3
19+
20+
- name: Set up Go
21+
uses: actions/setup-go@v3
22+
with:
23+
go-version: 'stable'
24+
25+
- name: Build and Test on Default Platform
26+
run: |
27+
go build -v ./...
28+
go test -v ./...
29+
30+
- name: Delete Existing Release Assets
31+
run: |
32+
release_id=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/oneclickvirt/pingtest/releases/tags/output" | jq -r '.id')
33+
echo "Deleting existing release assets..."
34+
assets=$(curl -s -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/oneclickvirt/pingtest/releases/$release_id/assets" | jq -r '.[] | .id')
35+
for asset in $assets; do
36+
echo "Deleting asset with ID: $asset"
37+
curl -X DELETE -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/oneclickvirt/pingtest/releases/assets/$asset"
38+
done
39+
sleep 60
40+
41+
release-binary:
42+
name: Release Go Binary
43+
runs-on: ubuntu-latest
44+
needs: build
45+
steps:
46+
- name: Checkout code
47+
uses: actions/checkout@v3
48+
49+
- name: Set up Go
50+
uses: actions/setup-go@v3
51+
with:
52+
go-version: 'stable'
53+
54+
- name: Build and Release
55+
run: |
56+
mkdir -p bin
57+
cd cmd
58+
CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -o ../bin/pingtest-${{ matrix.goos }}-${{ matrix.goarch }} -v -ldflags="-extldflags=-static" .
59+
60+
- name: Upload New Assets
61+
run: |
62+
release_id=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/oneclickvirt/pingtest/releases/tags/output" | jq -r '.id')
63+
echo "Uploading new assets to release..."
64+
for file in ./bin/*; do
65+
echo "Uploading $file to release..."
66+
curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
67+
-H "Content-Type: application/octet-stream" \
68+
--data-binary @"$file" \
69+
"https://uploads.github.com/repos/oneclickvirt/pingtest/releases/$release_id/assets?name=$(basename "$file")"
70+
rm -rf $file
71+
done
72+
73+
strategy:
74+
matrix:
75+
goos: [windows, freebsd, openbsd, linux, darwin]
76+
goarch: [amd64, 386]
77+
exclude:
78+
- goarch: 386
79+
goos: darwin
80+
include:
81+
- goos: windows
82+
goarch: 386
83+
- goos: windows
84+
goarch: amd64
85+
- goos: windows
86+
goarch: arm64
87+
- goos: windows
88+
goarch: arm
89+
goarm: 7
90+
- goos: darwin
91+
goarch: arm64
92+
- goos: linux
93+
goarch: arm
94+
goarm: 7
95+
- goos: linux
96+
goarch: arm64
97+
- goos: linux
98+
goarch: riscv64
99+
- goos: linux
100+
goarch: mips64
101+
- goos: linux
102+
goarch: mips64le
103+
- goos: linux
104+
goarch: mipsle
105+
- goos: linux
106+
goarch: mips
107+
- goos: linux
108+
goarch: ppc64
109+
- goos: linux
110+
goarch: ppc64le
111+
- goos: freebsd
112+
goarch: arm64
113+
- goos: freebsd
114+
goarch: arm
115+
goarm: 7
116+
- goos: openbsd
117+
goarch: arm64
118+
- goos: openbsd
119+
goarch: arm
120+
goarm: 7
121+
# - goos: linux
122+
# goarch: mipsle
123+
# gomips: softfloat
124+
# - goos: linux
125+
# goarch: mips
126+
# gomips: softfloat
127+
# - goos: linux
128+
# goarch: arm
129+
# goarm: 6
130+
# - goos: linux
131+
# goarch: arm
132+
# goarm: 5

README.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,56 @@
1-
# pingtest
1+
# pingtest
2+
3+
[![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Foneclickvirt%2Fpingtest&count_bg=%232EFFF8&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false)](https://www.spiritlhl.net)
4+
国内测速节点三网测ping模块
5+
6+
## 说明
7+
8+
- [x] 基于[speedtest.net-爬虫](https://github.com/spiritLHLS/speedtest.net-CN-ID)[speedtest.cn-爬虫](https://github.com/spiritLHLS/speedtest.cn-CN-ID)的数据
9+
- [x] 主体逻辑借鉴了[ecsspeed](https://github.com/spiritLHLS/ecsspeed)
10+
11+
## 使用
12+
13+
下载及安装
14+
15+
```
16+
curl https://raw.githubusercontent.com/oneclickvirt/pingtest/main/pt_install.sh -sSf | bash
17+
```
18+
19+
20+
21+
```
22+
curl https://cdn.spiritlhl.net/https://raw.githubusercontent.com/oneclickvirt/pingtest/main/pt_install.sh -sSf | bash
23+
```
24+
25+
使用
26+
27+
```
28+
pt
29+
```
30+
31+
32+
33+
```
34+
./pt
35+
```
36+
37+
进行测试
38+
39+
无环境依赖,理论上适配所有系统和主流架构,更多架构请查看 https://github.com/oneclickvirt/pingtest/releases/tag/output
40+
41+
```
42+
43+
```
44+
45+
## 卸载
46+
47+
```
48+
rm -rf /root/spt
49+
rm -rf /usr/bin/spt
50+
```
51+
52+
## 在Golang中使用
53+
54+
```
55+
go get github.com/oneclickvirt/pingtest@latest
56+
```

cmd/main.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"net/http"
7+
"os"
8+
9+
. "github.com/oneclickvirt/defaultset"
10+
"github.com/oneclickvirt/pingtest/model"
11+
"github.com/oneclickvirt/pingtest/pt"
12+
)
13+
14+
func main() {
15+
go func() {
16+
http.Get("https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Foneclickvirt%2Fpingtest&count_bg=%2323E01C&title_bg=%23555555&icon=sonarcloud.svg&icon_color=%23E7E7E7&title=hits&edge_flat=false")
17+
}()
18+
fmt.Println("项目地址:", Blue("https://github.com/oneclickvirt/pingtest"))
19+
var showVersion, help bool
20+
var language string
21+
pingtestFlag := flag.NewFlagSet("cputest", flag.ContinueOnError)
22+
pingtestFlag.BoolVar(&help, "h", false, "Show help information")
23+
pingtestFlag.BoolVar(&showVersion, "v", false, "Show version")
24+
pingtestFlag.StringVar(&language, "l", "", "Language parameter (en or zh)")
25+
pingtestFlag.Parse(os.Args[1:])
26+
if help {
27+
fmt.Printf("Usage: %s [options]\n", os.Args[0])
28+
pingtestFlag.PrintDefaults()
29+
return
30+
}
31+
if showVersion {
32+
fmt.Println(model.PingTestVersion)
33+
return
34+
}
35+
res := pt.PingTest()
36+
fmt.Printf(res)
37+
}

cmd/main_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import "testing"
4+
5+
func TestM(t *testing.T) {
6+
main()
7+
}

go.mod

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module github.com/oneclickvirt/pingtest
2+
3+
go 1.22.4
4+
5+
require (
6+
github.com/oneclickvirt/defaultset v0.0.2-20240624082446
7+
github.com/prometheus-community/pro-bing v0.4.0
8+
)
9+
10+
require (
11+
github.com/google/uuid v1.6.0 // indirect
12+
go.uber.org/multierr v1.10.0 // indirect
13+
go.uber.org/zap v1.27.0 // indirect
14+
golang.org/x/net v0.21.0 // indirect
15+
golang.org/x/sync v0.6.0 // indirect
16+
golang.org/x/sys v0.17.0 // indirect
17+
)

go.sum

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
4+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
5+
github.com/oneclickvirt/defaultset v0.0.2-20240624082446 h1:5Pg3mK/u/vQvSz7anu0nxzrNdELi/AcDAU1mMsmPzyc=
6+
github.com/oneclickvirt/defaultset v0.0.2-20240624082446/go.mod h1:e9Jt4tf2sbemCtc84/XgKcHy9EZ2jkc5x2sW1NiJS+E=
7+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
8+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
9+
github.com/prometheus-community/pro-bing v0.4.0 h1:YMbv+i08gQz97OZZBwLyvmmQEEzyfyrrjEaAchdy3R4=
10+
github.com/prometheus-community/pro-bing v0.4.0/go.mod h1:b7wRYZtCcPmt4Sz319BykUU241rWLe1VFXyiyWK/dH4=
11+
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
12+
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
13+
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
14+
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
15+
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
16+
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
17+
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
18+
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
19+
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
20+
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
21+
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
22+
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
23+
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
24+
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
25+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
26+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

model/model.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package model
2+
3+
const PingTestVersion = "v0.0.1"
4+
5+
var EnableLoger = false
6+
7+
var (
8+
NetCMCC = "https://raw.githubusercontent.com/spiritLHLS/speedtest.net-CN-ID/main/CN_Mobile.csv"
9+
NetCT = "https://raw.githubusercontent.com/spiritLHLS/speedtest.net-CN-ID/main/CN_Telecom.csv"
10+
NetCU = "https://raw.githubusercontent.com/spiritLHLS/speedtest.net-CN-ID/main/CN_Unicom.csv"
11+
NetHK = "https://raw.githubusercontent.com/spiritLHLS/speedtest.net-CN-ID/main/HK.csv"
12+
NetJP = "https://raw.githubusercontent.com/spiritLHLS/speedtest.net-CN-ID/main/JP.csv"
13+
NetTW = "https://raw.githubusercontent.com/spiritLHLS/speedtest.net-CN-ID/main/TW.csv"
14+
NetSG = "https://raw.githubusercontent.com/spiritLHLS/speedtest.net-CN-ID/main/SG.csv"
15+
NetGlobal = "https://raw.githubusercontent.com/spiritLHLS/speedtest.net-CN-ID/main/ls_sg_hk_jp.csv"
16+
17+
CnCMCC = "https://raw.githubusercontent.com/spiritLHLS/speedtest.cn-CN-ID/main/mobile.csv"
18+
CnCT = "https://raw.githubusercontent.com/spiritLHLS/speedtest.cn-CN-ID/main/telecom.csv"
19+
CnCU = "https://raw.githubusercontent.com/spiritLHLS/speedtest.cn-CN-ID/main/unicom.csv"
20+
CnHK = "https://raw.githubusercontent.com/spiritLHLS/speedtest.cn-CN-ID/main/HK.csv"
21+
CnJP = "https://raw.githubusercontent.com/spiritLHLS/speedtest.cn-CN-ID/main/JP.csv"
22+
CnTW = "https://raw.githubusercontent.com/spiritLHLS/speedtest.cn-CN-ID/main/TW.csv"
23+
CnSG = "https://raw.githubusercontent.com/spiritLHLS/speedtest.cn-CN-ID/main/SG.csv"
24+
25+
CdnList = []string{
26+
"http://cdn0.spiritlhl.top/",
27+
"http://cdn1.spiritlhl.top/",
28+
"http://cdn1.spiritlhl.net/",
29+
"http://cdn3.spiritlhl.net/",
30+
"http://cdn2.spiritlhl.net/",
31+
}
32+
)

0 commit comments

Comments
 (0)