mirror of
http://bgp.hk.skcks.cn:10088/github.com/oneclickvirt/ecs
synced 2026-04-21 05:10:32 +08:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b87d169a3 | ||
|
|
b8fe9d3d98 | ||
|
|
8f46bd3f4f | ||
|
|
e8c4b2b4a7 | ||
|
|
8016a8fe93 | ||
|
|
bf0030dc49 |
56
api/api.go
Normal file
56
api/api.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package api
|
||||
|
||||
const (
|
||||
// Version API版本号
|
||||
Version = "v1.0.0"
|
||||
|
||||
// DefaultVersion 默认的ECS版本号
|
||||
DefaultVersion = "v0.1.114"
|
||||
)
|
||||
|
||||
// 测试方法常量
|
||||
const (
|
||||
// CPU测试方法
|
||||
CpuMethodSysbench = "sysbench"
|
||||
CpuMethodGeekbench = "geekbench"
|
||||
CpuMethodWinsat = "winsat"
|
||||
|
||||
// 内存测试方法
|
||||
MemoryMethodStream = "stream"
|
||||
MemoryMethodSysbench = "sysbench"
|
||||
MemoryMethodDD = "dd"
|
||||
MemoryMethodWinsat = "winsat"
|
||||
|
||||
// 硬盘测试方法
|
||||
DiskMethodFio = "fio"
|
||||
DiskMethodDD = "dd"
|
||||
DiskMethodWinsat = "winsat"
|
||||
|
||||
// 线程模式
|
||||
ThreadModeSingle = "single"
|
||||
ThreadModeMulti = "multi"
|
||||
|
||||
// 语言选项
|
||||
LanguageZH = "zh"
|
||||
LanguageEN = "en"
|
||||
|
||||
// IP检测类型
|
||||
CheckTypeIPv4 = "ipv4"
|
||||
CheckTypeIPv6 = "ipv6"
|
||||
CheckTypeAuto = "auto"
|
||||
|
||||
// 测速平台
|
||||
PlatformCN = "cn"
|
||||
PlatformNet = "net"
|
||||
|
||||
// 运营商类型
|
||||
OperatorCMCC = "cmcc" // 中国移动
|
||||
OperatorCU = "cu" // 中国联通
|
||||
OperatorCT = "ct" // 中国电信
|
||||
OperatorGlobal = "global" // 全球节点
|
||||
OperatorOther = "other" // 其他
|
||||
OperatorHK = "hk" // 香港
|
||||
OperatorTW = "tw" // 台湾
|
||||
OperatorJP = "jp" // 日本
|
||||
OperatorSG = "sg" // 新加坡
|
||||
)
|
||||
259
api/config.go
Normal file
259
api/config.go
Normal file
@@ -0,0 +1,259 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/oneclickvirt/ecs/internal/params"
|
||||
)
|
||||
|
||||
// Config 配置接口,导出用于外部调用
|
||||
type Config = params.Config
|
||||
|
||||
// NewConfig 创建默认配置
|
||||
// version: 版本号字符串
|
||||
func NewConfig(version string) *Config {
|
||||
return params.NewConfig(version)
|
||||
}
|
||||
|
||||
// NewDefaultConfig 创建默认配置(使用默认版本号)
|
||||
func NewDefaultConfig() *Config {
|
||||
return params.NewConfig("v0.1.114")
|
||||
}
|
||||
|
||||
// ConfigOption 配置选项函数类型
|
||||
type ConfigOption func(*Config)
|
||||
|
||||
// WithLanguage 设置语言
|
||||
func WithLanguage(lang string) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.Language = lang
|
||||
}
|
||||
}
|
||||
|
||||
// WithCpuTestMethod 设置CPU测试方法
|
||||
// method: "sysbench" 或 "geekbench"
|
||||
func WithCpuTestMethod(method string) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.CpuTestMethod = method
|
||||
}
|
||||
}
|
||||
|
||||
// WithCpuTestThreadMode 设置CPU测试线程模式
|
||||
// mode: "single" 或 "multi"
|
||||
func WithCpuTestThreadMode(mode string) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.CpuTestThreadMode = mode
|
||||
}
|
||||
}
|
||||
|
||||
// WithMemoryTestMethod 设置内存测试方法
|
||||
// method: "stream", "sysbench", "dd"
|
||||
func WithMemoryTestMethod(method string) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.MemoryTestMethod = method
|
||||
}
|
||||
}
|
||||
|
||||
// WithDiskTestMethod 设置硬盘测试方法
|
||||
// method: "fio" 或 "dd"
|
||||
func WithDiskTestMethod(method string) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.DiskTestMethod = method
|
||||
}
|
||||
}
|
||||
|
||||
// WithDiskTestPath 设置硬盘测试路径
|
||||
func WithDiskTestPath(path string) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.DiskTestPath = path
|
||||
}
|
||||
}
|
||||
|
||||
// WithDiskMultiCheck 设置是否进行硬盘多路径检测
|
||||
func WithDiskMultiCheck(enable bool) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.DiskMultiCheck = enable
|
||||
}
|
||||
}
|
||||
|
||||
// WithSpeedTestNum 设置测速节点数量
|
||||
func WithSpeedTestNum(num int) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.SpNum = num
|
||||
}
|
||||
}
|
||||
|
||||
// WithWidth 设置输出宽度
|
||||
func WithWidth(width int) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.Width = width
|
||||
}
|
||||
}
|
||||
|
||||
// WithFilePath 设置输出文件路径
|
||||
func WithFilePath(path string) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.FilePath = path
|
||||
}
|
||||
}
|
||||
|
||||
// WithEnableUpload 设置是否启用上传
|
||||
func WithEnableUpload(enable bool) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.EnableUpload = enable
|
||||
}
|
||||
}
|
||||
|
||||
// WithEnableLogger 设置是否启用日志
|
||||
func WithEnableLogger(enable bool) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.EnableLogger = enable
|
||||
}
|
||||
}
|
||||
|
||||
// WithBasicTest 设置是否执行基础信息测试
|
||||
func WithBasicTest(enable bool) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.BasicStatus = enable
|
||||
}
|
||||
}
|
||||
|
||||
// WithCpuTest 设置是否执行CPU测试
|
||||
func WithCpuTest(enable bool) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.CpuTestStatus = enable
|
||||
}
|
||||
}
|
||||
|
||||
// WithMemoryTest 设置是否执行内存测试
|
||||
func WithMemoryTest(enable bool) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.MemoryTestStatus = enable
|
||||
}
|
||||
}
|
||||
|
||||
// WithDiskTest 设置是否执行硬盘测试
|
||||
func WithDiskTest(enable bool) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.DiskTestStatus = enable
|
||||
}
|
||||
}
|
||||
|
||||
// WithUnlockTest 设置是否执行流媒体解锁测试
|
||||
func WithUnlockTest(enable bool) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.UtTestStatus = enable
|
||||
}
|
||||
}
|
||||
|
||||
// WithSecurityTest 设置是否执行IP质量测试
|
||||
func WithSecurityTest(enable bool) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.SecurityTestStatus = enable
|
||||
}
|
||||
}
|
||||
|
||||
// WithEmailTest 设置是否执行邮件端口测试
|
||||
func WithEmailTest(enable bool) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.EmailTestStatus = enable
|
||||
}
|
||||
}
|
||||
|
||||
// WithBacktraceTest 设置是否执行回程路由测试
|
||||
func WithBacktraceTest(enable bool) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.BacktraceStatus = enable
|
||||
}
|
||||
}
|
||||
|
||||
// WithNt3Test 设置是否执行三网路由测试
|
||||
func WithNt3Test(enable bool) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.Nt3Status = enable
|
||||
}
|
||||
}
|
||||
|
||||
// WithSpeedTest 设置是否执行测速测试
|
||||
func WithSpeedTest(enable bool) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.SpeedTestStatus = enable
|
||||
}
|
||||
}
|
||||
|
||||
// WithPingTest 设置是否执行PING测试
|
||||
func WithPingTest(enable bool) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.PingTestStatus = enable
|
||||
}
|
||||
}
|
||||
|
||||
// WithTgdcTest 设置是否执行Telegram DC测试
|
||||
func WithTgdcTest(enable bool) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.TgdcTestStatus = enable
|
||||
}
|
||||
}
|
||||
|
||||
// WithWebTest 设置是否执行网站测试
|
||||
func WithWebTest(enable bool) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.WebTestStatus = enable
|
||||
}
|
||||
}
|
||||
|
||||
// WithNt3CheckType 设置三网路由检测类型
|
||||
// checkType: "ipv4", "ipv6" 或 "auto"
|
||||
func WithNt3CheckType(checkType string) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.Nt3CheckType = checkType
|
||||
}
|
||||
}
|
||||
|
||||
// WithNt3Location 设置三网路由检测位置
|
||||
func WithNt3Location(location string) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.Nt3Location = location
|
||||
}
|
||||
}
|
||||
|
||||
// WithAutoChangeDiskMethod 设置是否自动切换硬盘测试方法
|
||||
func WithAutoChangeDiskMethod(enable bool) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.AutoChangeDiskMethod = enable
|
||||
}
|
||||
}
|
||||
|
||||
// WithOnlyChinaTest 设置是否只进行国内测试
|
||||
func WithOnlyChinaTest(enable bool) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.OnlyChinaTest = enable
|
||||
}
|
||||
}
|
||||
|
||||
// WithMenuMode 设置是否启用菜单模式
|
||||
func WithMenuMode(enable bool) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.MenuMode = enable
|
||||
}
|
||||
}
|
||||
|
||||
// WithOnlyIpInfoCheck 设置是否只进行IP信息检测
|
||||
func WithOnlyIpInfoCheck(enable bool) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.OnlyIpInfoCheck = enable
|
||||
}
|
||||
}
|
||||
|
||||
// WithChoice 设置菜单选择
|
||||
func WithChoice(choice string) ConfigOption {
|
||||
return func(c *Config) {
|
||||
c.Choice = choice
|
||||
}
|
||||
}
|
||||
|
||||
// ApplyOptions 应用配置选项
|
||||
func ApplyOptions(config *Config, options ...ConfigOption) *Config {
|
||||
for _, opt := range options {
|
||||
opt(config)
|
||||
}
|
||||
return config
|
||||
}
|
||||
27
api/menu.go
Normal file
27
api/menu.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/oneclickvirt/ecs/internal/menu"
|
||||
"github.com/oneclickvirt/ecs/utils"
|
||||
)
|
||||
|
||||
// GetMenuChoice 获取用户菜单选择
|
||||
// language: 语言 ("zh" 或 "en")
|
||||
// 返回: 用户选择的选项
|
||||
func GetMenuChoice(language string) string {
|
||||
return menu.GetMenuChoice(language)
|
||||
}
|
||||
|
||||
// PrintMenuOptions 打印菜单选项
|
||||
// preCheck: 网络检查结果
|
||||
// config: 配置对象
|
||||
func PrintMenuOptions(preCheck utils.NetCheckResult, config *Config) {
|
||||
menu.PrintMenuOptions(preCheck, config)
|
||||
}
|
||||
|
||||
// HandleMenuMode 处理菜单模式
|
||||
// preCheck: 网络检查结果
|
||||
// config: 配置对象
|
||||
func HandleMenuMode(preCheck utils.NetCheckResult, config *Config) {
|
||||
menu.HandleMenuMode(preCheck, config)
|
||||
}
|
||||
187
api/runner.go
Normal file
187
api/runner.go
Normal file
@@ -0,0 +1,187 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/oneclickvirt/ecs/internal/runner"
|
||||
"github.com/oneclickvirt/ecs/utils"
|
||||
)
|
||||
|
||||
// RunResult 运行结果
|
||||
type RunResult struct {
|
||||
Output string // 完整输出
|
||||
Duration time.Duration // 运行时长
|
||||
StartTime time.Time // 开始时间
|
||||
EndTime time.Time // 结束时间
|
||||
}
|
||||
|
||||
// RunAllTests 执行所有测试(高级接口)
|
||||
// preCheck: 网络检查结果
|
||||
// config: 配置对象
|
||||
// 返回: 运行结果
|
||||
func RunAllTests(preCheck utils.NetCheckResult, config *Config) *RunResult {
|
||||
var (
|
||||
wg1, wg2, wg3 sync.WaitGroup
|
||||
basicInfo, securityInfo, emailInfo, mediaInfo, ptInfo string
|
||||
output, tempOutput string
|
||||
outputMutex sync.Mutex
|
||||
infoMutex sync.Mutex
|
||||
)
|
||||
|
||||
startTime := time.Now()
|
||||
|
||||
switch config.Language {
|
||||
case "zh":
|
||||
runner.RunChineseTests(preCheck, config, &wg1, &wg2, &wg3,
|
||||
&basicInfo, &securityInfo, &emailInfo, &mediaInfo, &ptInfo,
|
||||
&output, tempOutput, startTime, &outputMutex, &infoMutex)
|
||||
case "en":
|
||||
runner.RunEnglishTests(preCheck, config, &wg1, &wg2, &wg3,
|
||||
&basicInfo, &securityInfo, &emailInfo, &mediaInfo, &ptInfo,
|
||||
&output, tempOutput, startTime, &outputMutex, &infoMutex)
|
||||
default:
|
||||
runner.RunChineseTests(preCheck, config, &wg1, &wg2, &wg3,
|
||||
&basicInfo, &securityInfo, &emailInfo, &mediaInfo, &ptInfo,
|
||||
&output, tempOutput, startTime, &outputMutex, &infoMutex)
|
||||
}
|
||||
|
||||
endTime := time.Now()
|
||||
|
||||
return &RunResult{
|
||||
Output: output,
|
||||
Duration: endTime.Sub(startTime),
|
||||
StartTime: startTime,
|
||||
EndTime: endTime,
|
||||
}
|
||||
}
|
||||
|
||||
// RunBasicTests 运行基础信息测试
|
||||
func RunBasicTests(preCheck utils.NetCheckResult, config *Config) string {
|
||||
var (
|
||||
basicInfo, securityInfo string
|
||||
output, tempOutput string
|
||||
outputMutex sync.Mutex
|
||||
)
|
||||
return runner.RunBasicTests(preCheck, config, &basicInfo, &securityInfo, output, tempOutput, &outputMutex)
|
||||
}
|
||||
|
||||
// RunCPUTest 运行CPU测试
|
||||
func RunCPUTest(config *Config) string {
|
||||
var (
|
||||
output, tempOutput string
|
||||
outputMutex sync.Mutex
|
||||
)
|
||||
return runner.RunCPUTest(config, output, tempOutput, &outputMutex)
|
||||
}
|
||||
|
||||
// RunMemoryTest 运行内存测试
|
||||
func RunMemoryTest(config *Config) string {
|
||||
var (
|
||||
output, tempOutput string
|
||||
outputMutex sync.Mutex
|
||||
)
|
||||
return runner.RunMemoryTest(config, output, tempOutput, &outputMutex)
|
||||
}
|
||||
|
||||
// RunDiskTest 运行硬盘测试
|
||||
func RunDiskTest(config *Config) string {
|
||||
var (
|
||||
output, tempOutput string
|
||||
outputMutex sync.Mutex
|
||||
)
|
||||
return runner.RunDiskTest(config, output, tempOutput, &outputMutex)
|
||||
}
|
||||
|
||||
// RunIpInfoCheck 执行IP信息检测
|
||||
func RunIpInfoCheck(config *Config) string {
|
||||
var (
|
||||
output, tempOutput string
|
||||
outputMutex sync.Mutex
|
||||
)
|
||||
return runner.RunIpInfoCheck(config, output, tempOutput, &outputMutex)
|
||||
}
|
||||
|
||||
// RunStreamingTests 运行流媒体测试
|
||||
func RunStreamingTests(config *Config, mediaInfo string) string {
|
||||
var (
|
||||
wg1 sync.WaitGroup
|
||||
output, tempOutput string
|
||||
outputMutex sync.Mutex
|
||||
infoMutex sync.Mutex
|
||||
)
|
||||
return runner.RunStreamingTests(config, &wg1, &mediaInfo, output, tempOutput, &outputMutex, &infoMutex)
|
||||
}
|
||||
|
||||
// RunSecurityTests 运行安全测试
|
||||
func RunSecurityTests(config *Config, securityInfo string) string {
|
||||
var (
|
||||
output, tempOutput string
|
||||
outputMutex sync.Mutex
|
||||
)
|
||||
return runner.RunSecurityTests(config, securityInfo, output, tempOutput, &outputMutex)
|
||||
}
|
||||
|
||||
// RunEmailTests 运行邮件端口测试
|
||||
func RunEmailTests(config *Config, emailInfo string) string {
|
||||
var (
|
||||
wg2 sync.WaitGroup
|
||||
output, tempOutput string
|
||||
outputMutex sync.Mutex
|
||||
infoMutex sync.Mutex
|
||||
)
|
||||
return runner.RunEmailTests(config, &wg2, &emailInfo, output, tempOutput, &outputMutex, &infoMutex)
|
||||
}
|
||||
|
||||
// RunNetworkTests 运行网络测试(中文模式)
|
||||
func RunNetworkTests(config *Config, ptInfo string) string {
|
||||
var (
|
||||
wg3 sync.WaitGroup
|
||||
output, tempOutput string
|
||||
outputMutex sync.Mutex
|
||||
infoMutex sync.Mutex
|
||||
)
|
||||
return runner.RunNetworkTests(config, &wg3, &ptInfo, output, tempOutput, &outputMutex, &infoMutex)
|
||||
}
|
||||
|
||||
// RunSpeedTests 运行测速测试(中文模式)
|
||||
func RunSpeedTests(config *Config) string {
|
||||
var (
|
||||
output, tempOutput string
|
||||
outputMutex sync.Mutex
|
||||
)
|
||||
return runner.RunSpeedTests(config, output, tempOutput, &outputMutex)
|
||||
}
|
||||
|
||||
// RunEnglishNetworkTests 运行网络测试(英文模式)
|
||||
func RunEnglishNetworkTests(config *Config, ptInfo string) string {
|
||||
var (
|
||||
wg3 sync.WaitGroup
|
||||
output, tempOutput string
|
||||
outputMutex sync.Mutex
|
||||
)
|
||||
return runner.RunEnglishNetworkTests(config, &wg3, &ptInfo, output, tempOutput, &outputMutex)
|
||||
}
|
||||
|
||||
// RunEnglishSpeedTests 运行测速测试(英文模式)
|
||||
func RunEnglishSpeedTests(config *Config) string {
|
||||
var (
|
||||
output, tempOutput string
|
||||
outputMutex sync.Mutex
|
||||
)
|
||||
return runner.RunEnglishSpeedTests(config, output, tempOutput, &outputMutex)
|
||||
}
|
||||
|
||||
// AppendTimeInfo 添加时间信息
|
||||
func AppendTimeInfo(config *Config, output string, startTime time.Time) string {
|
||||
var (
|
||||
tempOutput string
|
||||
outputMutex sync.Mutex
|
||||
)
|
||||
return runner.AppendTimeInfo(config, output, tempOutput, startTime, &outputMutex)
|
||||
}
|
||||
|
||||
// HandleUploadResults 处理上传结果
|
||||
func HandleUploadResults(config *Config, output string) {
|
||||
runner.HandleUploadResults(config, output)
|
||||
}
|
||||
101
api/tests.go
Normal file
101
api/tests.go
Normal file
@@ -0,0 +1,101 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/oneclickvirt/ecs/internal/tests"
|
||||
)
|
||||
|
||||
// TestResult 测试结果结构
|
||||
type TestResult struct {
|
||||
TestMethod string // 实际使用的测试方法
|
||||
Output string // 测试输出结果
|
||||
Success bool // 是否成功
|
||||
Error error // 错误信息
|
||||
}
|
||||
|
||||
// CpuTest CPU测试公共接口
|
||||
// language: 语言 ("zh" 或 "en")
|
||||
// testMethod: 测试方法 ("sysbench" 或 "geekbench")
|
||||
// testThread: 线程模式 ("single" 或 "multi")
|
||||
// 返回: (实际测试方法, 测试结果)
|
||||
func CpuTest(language, testMethod, testThread string) (string, string) {
|
||||
return tests.CpuTest(language, testMethod, testThread)
|
||||
}
|
||||
|
||||
// MemoryTest 内存测试公共接口
|
||||
// language: 语言 ("zh" 或 "en")
|
||||
// testMethod: 测试方法 ("stream", "sysbench", "dd")
|
||||
// 返回: (实际测试方法, 测试结果)
|
||||
func MemoryTest(language, testMethod string) (string, string) {
|
||||
return tests.MemoryTest(language, testMethod)
|
||||
}
|
||||
|
||||
// DiskTest 硬盘测试公共接口
|
||||
// language: 语言 ("zh" 或 "en")
|
||||
// testMethod: 测试方法 ("fio" 或 "dd")
|
||||
// testPath: 测试路径
|
||||
// isMultiCheck: 是否多路径检测
|
||||
// autoChange: 是否自动切换方法
|
||||
// 返回: (实际测试方法, 测试结果)
|
||||
func DiskTest(language, testMethod, testPath string, isMultiCheck, autoChange bool) (string, string) {
|
||||
return tests.DiskTest(language, testMethod, testPath, isMultiCheck, autoChange)
|
||||
}
|
||||
|
||||
// MediaTest 流媒体解锁测试公共接口
|
||||
// language: 语言 ("zh" 或 "en")
|
||||
// 返回: 测试结果
|
||||
func MediaTest(language string) string {
|
||||
return tests.MediaTest(language)
|
||||
}
|
||||
|
||||
// SpeedTestShowHead 显示测速表头
|
||||
// language: 语言 ("zh" 或 "en")
|
||||
func SpeedTestShowHead(language string) {
|
||||
tests.ShowHead(language)
|
||||
}
|
||||
|
||||
// SpeedTestNearby 就近节点测速
|
||||
func SpeedTestNearby() {
|
||||
tests.NearbySP()
|
||||
}
|
||||
|
||||
// SpeedTestCustom 自定义测速
|
||||
// platform: 平台 ("cn" 或 "net")
|
||||
// operator: 运营商 ("cmcc", "cu", "ct", "global", "other" 等)
|
||||
// num: 测试节点数量
|
||||
// language: 语言 ("zh" 或 "en")
|
||||
func SpeedTestCustom(platform, operator string, num int, language string) {
|
||||
tests.CustomSP(platform, operator, num, language)
|
||||
}
|
||||
|
||||
// NextTrace3Check 三网路由追踪测试
|
||||
// language: 语言 ("zh" 或 "en")
|
||||
// location: 位置
|
||||
// checkType: 检测类型 ("ipv4", "ipv6")
|
||||
func NextTrace3Check(language, location, checkType string) {
|
||||
tests.NextTrace3Check(language, location, checkType)
|
||||
}
|
||||
|
||||
// UpstreamsCheck 上游及回程线路检测
|
||||
func UpstreamsCheck() {
|
||||
tests.UpstreamsCheck()
|
||||
}
|
||||
|
||||
// GetIPv4Address 获取当前IPv4地址
|
||||
func GetIPv4Address() string {
|
||||
return tests.IPV4
|
||||
}
|
||||
|
||||
// GetIPv6Address 获取当前IPv6地址
|
||||
func GetIPv6Address() string {
|
||||
return tests.IPV6
|
||||
}
|
||||
|
||||
// SetIPv4Address 设置IPv4地址(用于测试)
|
||||
func SetIPv4Address(ipv4 string) {
|
||||
tests.IPV4 = ipv4
|
||||
}
|
||||
|
||||
// SetIPv6Address 设置IPv6地址(用于测试)
|
||||
func SetIPv6Address(ipv6 string) {
|
||||
tests.IPV6 = ipv6
|
||||
}
|
||||
91
api/utils.go
Normal file
91
api/utils.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/oneclickvirt/ecs/utils"
|
||||
)
|
||||
|
||||
// NetCheckResult 网络检查结果
|
||||
type NetCheckResult = utils.NetCheckResult
|
||||
|
||||
// StatsResponse 统计信息响应
|
||||
type StatsResponse = utils.StatsResponse
|
||||
|
||||
// GitHubRelease GitHub发布信息
|
||||
type GitHubRelease = utils.GitHubRelease
|
||||
|
||||
// CheckPublicAccess 检查公网访问能力
|
||||
// timeout: 超时时间
|
||||
// 返回: 网络检查结果
|
||||
func CheckPublicAccess(timeout time.Duration) NetCheckResult {
|
||||
return utils.CheckPublicAccess(timeout)
|
||||
}
|
||||
|
||||
// GetGoescStats 获取goecs统计信息
|
||||
// 返回: (统计响应, 错误)
|
||||
func GetGoescStats() (*StatsResponse, error) {
|
||||
return utils.GetGoescStats()
|
||||
}
|
||||
|
||||
// GetLatestEcsRelease 获取最新的ECS版本信息
|
||||
// 返回: (GitHub发布信息, 错误)
|
||||
func GetLatestEcsRelease() (*GitHubRelease, error) {
|
||||
return utils.GetLatestEcsRelease()
|
||||
}
|
||||
|
||||
// PrintHead 打印程序头部信息
|
||||
// language: 语言 ("zh" 或 "en")
|
||||
// width: 显示宽度
|
||||
// version: 版本号
|
||||
func PrintHead(language string, width int, version string) {
|
||||
utils.PrintHead(language, width, version)
|
||||
}
|
||||
|
||||
// PrintCenteredTitle 打印居中标题
|
||||
// title: 标题文本
|
||||
// width: 显示宽度
|
||||
func PrintCenteredTitle(title string, width int) {
|
||||
utils.PrintCenteredTitle(title, width)
|
||||
}
|
||||
|
||||
// ProcessAndUpload 处理并上传结果
|
||||
// output: 输出内容
|
||||
// filePath: 文件路径
|
||||
// enableUpload: 是否启用上传
|
||||
// 返回: (HTTP URL, HTTPS URL)
|
||||
func ProcessAndUpload(output, filePath string, enableUpload bool) (string, string) {
|
||||
return utils.ProcessAndUpload(output, filePath, enableUpload)
|
||||
}
|
||||
|
||||
// BasicsAndSecurityCheck 基础信息和安全检查
|
||||
// language: 语言
|
||||
// checkType: 检查类型
|
||||
// securityTestStatus: 是否执行安全测试
|
||||
// 返回: (IPv4地址, IPv6地址, 基础信息, 安全信息, 检查类型)
|
||||
func BasicsAndSecurityCheck(language, checkType string, securityTestStatus bool) (string, string, string, string, string) {
|
||||
return utils.BasicsAndSecurityCheck(language, checkType, securityTestStatus)
|
||||
}
|
||||
|
||||
// OnlyBasicsIpInfo 仅获取基础IP信息
|
||||
// language: 语言
|
||||
// 返回: (IPv4地址, IPv6地址, IP信息)
|
||||
func OnlyBasicsIpInfo(language string) (string, string, string) {
|
||||
return utils.OnlyBasicsIpInfo(language)
|
||||
}
|
||||
|
||||
// FormatGoecsNumber 格式化数字显示
|
||||
// num: 数字
|
||||
// 返回: 格式化后的字符串
|
||||
func FormatGoecsNumber(num int) string {
|
||||
return utils.FormatGoecsNumber(num)
|
||||
}
|
||||
|
||||
// PrintAndCapture 打印并捕获输出
|
||||
// fn: 执行的函数
|
||||
// tempOutput: 临时输出
|
||||
// existingOutput: 现有输出
|
||||
// 返回: 捕获的输出
|
||||
func PrintAndCapture(fn func(), tempOutput, existingOutput string) string {
|
||||
return utils.PrintAndCapture(fn, tempOutput, existingOutput)
|
||||
}
|
||||
4
go.mod
4
go.mod
@@ -4,7 +4,7 @@ go 1.25.4
|
||||
|
||||
require (
|
||||
github.com/imroc/req/v3 v3.54.0
|
||||
github.com/oneclickvirt/UnlockTests v0.0.34-20260130055000
|
||||
github.com/oneclickvirt/UnlockTests v0.0.35-20260207053956
|
||||
github.com/oneclickvirt/backtrace v0.0.8-20251109090457
|
||||
github.com/oneclickvirt/basics v0.0.16-20251112033526
|
||||
github.com/oneclickvirt/cputest v0.0.12-20251111095842
|
||||
@@ -16,7 +16,7 @@ require (
|
||||
github.com/oneclickvirt/pingtest v0.0.9-20251104112920
|
||||
github.com/oneclickvirt/portchecker v0.0.3-20250728015900
|
||||
github.com/oneclickvirt/privatespeedtest v0.0.1-20260112130218
|
||||
github.com/oneclickvirt/security v0.0.8-20260104113003
|
||||
github.com/oneclickvirt/security v0.0.8-20260202071316
|
||||
github.com/oneclickvirt/speedtest v0.0.11-20251102151740
|
||||
)
|
||||
|
||||
|
||||
8
go.sum
8
go.sum
@@ -96,8 +96,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/nxtrace/NTrace-core v1.5.0 h1:n+a/FObw/+CcqvhuSQiWcm1q+ODtfo7Wt3VmaIx504I=
|
||||
github.com/nxtrace/NTrace-core v1.5.0/go.mod h1:/jME48iJ7QaVTzsrTPQyTJ+yExhjeWjax2L6uBd4ckk=
|
||||
github.com/oneclickvirt/UnlockTests v0.0.34-20260130055000 h1:amgZH8QyTmgZ09t6j0Fi0SbSU03vhZIFjW/1/sOT70M=
|
||||
github.com/oneclickvirt/UnlockTests v0.0.34-20260130055000/go.mod h1:oOa6wj/qECtRMxwBO6D7o0L0F0Q/5sQ747OCnFQqoGE=
|
||||
github.com/oneclickvirt/UnlockTests v0.0.35-20260207053956 h1:yccGrw/sYOHZMaFJghPVN3Xn6JyTOXsEQc9v0I92k3M=
|
||||
github.com/oneclickvirt/UnlockTests v0.0.35-20260207053956/go.mod h1:oOa6wj/qECtRMxwBO6D7o0L0F0Q/5sQ747OCnFQqoGE=
|
||||
github.com/oneclickvirt/backtrace v0.0.8-20251109090457 h1:599/R/qMAtfPCPG1bPoi6KbjNJzVkKtxm8dvVIdtn5o=
|
||||
github.com/oneclickvirt/backtrace v0.0.8-20251109090457/go.mod h1:mj9TSow7FNszBb3bQj2Hhm41LwBo7HQP6sgaPtovKdM=
|
||||
github.com/oneclickvirt/basics v0.0.16-20251112033526 h1:bgoLaqStV3a6mbPiM++0mYizd278GVa6J6yeIiusV+A=
|
||||
@@ -126,8 +126,8 @@ github.com/oneclickvirt/portchecker v0.0.3-20250728015900 h1:AomzdppSOFB70AJESQh
|
||||
github.com/oneclickvirt/portchecker v0.0.3-20250728015900/go.mod h1:9sjMDPCd4Z40wkYB0S9gQPGH8YPtnNE1ZJthVIuHUzA=
|
||||
github.com/oneclickvirt/privatespeedtest v0.0.1-20260112130218 h1:h2k2fHtrsIIP/x/apEWkQGlTKuIumz8GrUR/df41YhE=
|
||||
github.com/oneclickvirt/privatespeedtest v0.0.1-20260112130218/go.mod h1:IXOlKKX4DUNqxOaW/K9bcdrBiWxo0jGSLXeBeo7NrTo=
|
||||
github.com/oneclickvirt/security v0.0.8-20260104113003 h1:NfmI83E+BAla+6ruFVDJIM5wsIi3ENH7FIcdn/kRhUI=
|
||||
github.com/oneclickvirt/security v0.0.8-20260104113003/go.mod h1:aPMIwqsz7wiUH1cqvtRr9+QcQRkKzlUWecDM6SGVddc=
|
||||
github.com/oneclickvirt/security v0.0.8-20260202071316 h1:ULZWXC99IzrdFEG05D2/MQklKAhztQNc6UYCE3fEQeU=
|
||||
github.com/oneclickvirt/security v0.0.8-20260202071316/go.mod h1:aPMIwqsz7wiUH1cqvtRr9+QcQRkKzlUWecDM6SGVddc=
|
||||
github.com/oneclickvirt/speedtest v0.0.11-20251102151740 h1:1NUrNt5ay6/xVNC5x62UrQjPqK8jgbKtyjBml/3boZg=
|
||||
github.com/oneclickvirt/speedtest v0.0.11-20251102151740/go.mod h1:fy0II2Wo7kDWVBKTwcHdodZwyfmJo0g8N9V02EwQDZE=
|
||||
github.com/oneclickvirt/stream v0.0.2-20250924154001 h1:GuJWdiPkoK84+y/+oHKr2Ghl3c/MzS9Z5m1nM+lMmy4=
|
||||
|
||||
2
goecs.go
2
goecs.go
@@ -27,7 +27,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ecsVersion = "v0.1.113" // 融合怪版本号
|
||||
ecsVersion = "v0.1.115" // 融合怪版本号
|
||||
configs = params.NewConfig(ecsVersion) // 全局配置实例
|
||||
userSetFlags = make(map[string]bool) // 用于跟踪哪些参数是用户显式设置的
|
||||
)
|
||||
|
||||
6
goecs.sh
6
goecs.sh
@@ -152,7 +152,7 @@ goecs_check() {
|
||||
os=$(uname -s 2>/dev/null || echo "Unknown")
|
||||
arch=$(uname -m 2>/dev/null || echo "Unknown")
|
||||
check_china
|
||||
ECS_VERSION="0.1.112"
|
||||
ECS_VERSION="0.1.114"
|
||||
for api in \
|
||||
"https://api.github.com/repos/oneclickvirt/ecs/releases/latest" \
|
||||
"https://githubapi.spiritlhl.workers.dev/repos/oneclickvirt/ecs/releases/latest" \
|
||||
@@ -164,8 +164,8 @@ goecs_check() {
|
||||
sleep 1
|
||||
done
|
||||
if [ -z "$ECS_VERSION" ]; then
|
||||
_yellow "Unable to get version info, using default version 0.1.112"
|
||||
ECS_VERSION="0.1.112"
|
||||
_yellow "Unable to get version info, using default version 0.1.114"
|
||||
ECS_VERSION="0.1.114"
|
||||
fi
|
||||
version_output=""
|
||||
for cmd_path in "goecs" "./goecs" "/usr/bin/goecs" "/usr/local/bin/goecs"; do
|
||||
|
||||
Reference in New Issue
Block a user