|
| 1 | +package api |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/oneclickvirt/ecs/internal/params" |
| 5 | +) |
| 6 | + |
| 7 | +// Config 配置接口,导出用于外部调用 |
| 8 | +type Config = params.Config |
| 9 | + |
| 10 | +// NewConfig 创建默认配置 |
| 11 | +// version: 版本号字符串 |
| 12 | +func NewConfig(version string) *Config { |
| 13 | + return params.NewConfig(version) |
| 14 | +} |
| 15 | + |
| 16 | +// NewDefaultConfig 创建默认配置(使用默认版本号) |
| 17 | +func NewDefaultConfig() *Config { |
| 18 | + return params.NewConfig("v0.1.114") |
| 19 | +} |
| 20 | + |
| 21 | +// ConfigOption 配置选项函数类型 |
| 22 | +type ConfigOption func(*Config) |
| 23 | + |
| 24 | +// WithLanguage 设置语言 |
| 25 | +func WithLanguage(lang string) ConfigOption { |
| 26 | + return func(c *Config) { |
| 27 | + c.Language = lang |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +// WithCpuTestMethod 设置CPU测试方法 |
| 32 | +// method: "sysbench" 或 "geekbench" |
| 33 | +func WithCpuTestMethod(method string) ConfigOption { |
| 34 | + return func(c *Config) { |
| 35 | + c.CpuTestMethod = method |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +// WithCpuTestThreadMode 设置CPU测试线程模式 |
| 40 | +// mode: "single" 或 "multi" |
| 41 | +func WithCpuTestThreadMode(mode string) ConfigOption { |
| 42 | + return func(c *Config) { |
| 43 | + c.CpuTestThreadMode = mode |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +// WithMemoryTestMethod 设置内存测试方法 |
| 48 | +// method: "stream", "sysbench", "dd" |
| 49 | +func WithMemoryTestMethod(method string) ConfigOption { |
| 50 | + return func(c *Config) { |
| 51 | + c.MemoryTestMethod = method |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +// WithDiskTestMethod 设置硬盘测试方法 |
| 56 | +// method: "fio" 或 "dd" |
| 57 | +func WithDiskTestMethod(method string) ConfigOption { |
| 58 | + return func(c *Config) { |
| 59 | + c.DiskTestMethod = method |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +// WithDiskTestPath 设置硬盘测试路径 |
| 64 | +func WithDiskTestPath(path string) ConfigOption { |
| 65 | + return func(c *Config) { |
| 66 | + c.DiskTestPath = path |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +// WithDiskMultiCheck 设置是否进行硬盘多路径检测 |
| 71 | +func WithDiskMultiCheck(enable bool) ConfigOption { |
| 72 | + return func(c *Config) { |
| 73 | + c.DiskMultiCheck = enable |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +// WithSpeedTestNum 设置测速节点数量 |
| 78 | +func WithSpeedTestNum(num int) ConfigOption { |
| 79 | + return func(c *Config) { |
| 80 | + c.SpNum = num |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +// WithWidth 设置输出宽度 |
| 85 | +func WithWidth(width int) ConfigOption { |
| 86 | + return func(c *Config) { |
| 87 | + c.Width = width |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +// WithFilePath 设置输出文件路径 |
| 92 | +func WithFilePath(path string) ConfigOption { |
| 93 | + return func(c *Config) { |
| 94 | + c.FilePath = path |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +// WithEnableUpload 设置是否启用上传 |
| 99 | +func WithEnableUpload(enable bool) ConfigOption { |
| 100 | + return func(c *Config) { |
| 101 | + c.EnableUpload = enable |
| 102 | + } |
| 103 | +} |
| 104 | + |
| 105 | +// WithEnableLogger 设置是否启用日志 |
| 106 | +func WithEnableLogger(enable bool) ConfigOption { |
| 107 | + return func(c *Config) { |
| 108 | + c.EnableLogger = enable |
| 109 | + } |
| 110 | +} |
| 111 | + |
| 112 | +// WithBasicTest 设置是否执行基础信息测试 |
| 113 | +func WithBasicTest(enable bool) ConfigOption { |
| 114 | + return func(c *Config) { |
| 115 | + c.BasicStatus = enable |
| 116 | + } |
| 117 | +} |
| 118 | + |
| 119 | +// WithCpuTest 设置是否执行CPU测试 |
| 120 | +func WithCpuTest(enable bool) ConfigOption { |
| 121 | + return func(c *Config) { |
| 122 | + c.CpuTestStatus = enable |
| 123 | + } |
| 124 | +} |
| 125 | + |
| 126 | +// WithMemoryTest 设置是否执行内存测试 |
| 127 | +func WithMemoryTest(enable bool) ConfigOption { |
| 128 | + return func(c *Config) { |
| 129 | + c.MemoryTestStatus = enable |
| 130 | + } |
| 131 | +} |
| 132 | + |
| 133 | +// WithDiskTest 设置是否执行硬盘测试 |
| 134 | +func WithDiskTest(enable bool) ConfigOption { |
| 135 | + return func(c *Config) { |
| 136 | + c.DiskTestStatus = enable |
| 137 | + } |
| 138 | +} |
| 139 | + |
| 140 | +// WithUnlockTest 设置是否执行流媒体解锁测试 |
| 141 | +func WithUnlockTest(enable bool) ConfigOption { |
| 142 | + return func(c *Config) { |
| 143 | + c.UtTestStatus = enable |
| 144 | + } |
| 145 | +} |
| 146 | + |
| 147 | +// WithSecurityTest 设置是否执行IP质量测试 |
| 148 | +func WithSecurityTest(enable bool) ConfigOption { |
| 149 | + return func(c *Config) { |
| 150 | + c.SecurityTestStatus = enable |
| 151 | + } |
| 152 | +} |
| 153 | + |
| 154 | +// WithEmailTest 设置是否执行邮件端口测试 |
| 155 | +func WithEmailTest(enable bool) ConfigOption { |
| 156 | + return func(c *Config) { |
| 157 | + c.EmailTestStatus = enable |
| 158 | + } |
| 159 | +} |
| 160 | + |
| 161 | +// WithBacktraceTest 设置是否执行回程路由测试 |
| 162 | +func WithBacktraceTest(enable bool) ConfigOption { |
| 163 | + return func(c *Config) { |
| 164 | + c.BacktraceStatus = enable |
| 165 | + } |
| 166 | +} |
| 167 | + |
| 168 | +// WithNt3Test 设置是否执行三网路由测试 |
| 169 | +func WithNt3Test(enable bool) ConfigOption { |
| 170 | + return func(c *Config) { |
| 171 | + c.Nt3Status = enable |
| 172 | + } |
| 173 | +} |
| 174 | + |
| 175 | +// WithSpeedTest 设置是否执行测速测试 |
| 176 | +func WithSpeedTest(enable bool) ConfigOption { |
| 177 | + return func(c *Config) { |
| 178 | + c.SpeedTestStatus = enable |
| 179 | + } |
| 180 | +} |
| 181 | + |
| 182 | +// WithPingTest 设置是否执行PING测试 |
| 183 | +func WithPingTest(enable bool) ConfigOption { |
| 184 | + return func(c *Config) { |
| 185 | + c.PingTestStatus = enable |
| 186 | + } |
| 187 | +} |
| 188 | + |
| 189 | +// WithTgdcTest 设置是否执行Telegram DC测试 |
| 190 | +func WithTgdcTest(enable bool) ConfigOption { |
| 191 | + return func(c *Config) { |
| 192 | + c.TgdcTestStatus = enable |
| 193 | + } |
| 194 | +} |
| 195 | + |
| 196 | +// WithWebTest 设置是否执行网站测试 |
| 197 | +func WithWebTest(enable bool) ConfigOption { |
| 198 | + return func(c *Config) { |
| 199 | + c.WebTestStatus = enable |
| 200 | + } |
| 201 | +} |
| 202 | + |
| 203 | +// WithNt3CheckType 设置三网路由检测类型 |
| 204 | +// checkType: "ipv4", "ipv6" 或 "auto" |
| 205 | +func WithNt3CheckType(checkType string) ConfigOption { |
| 206 | + return func(c *Config) { |
| 207 | + c.Nt3CheckType = checkType |
| 208 | + } |
| 209 | +} |
| 210 | + |
| 211 | +// WithNt3Location 设置三网路由检测位置 |
| 212 | +func WithNt3Location(location string) ConfigOption { |
| 213 | + return func(c *Config) { |
| 214 | + c.Nt3Location = location |
| 215 | + } |
| 216 | +} |
| 217 | + |
| 218 | +// WithAutoChangeDiskMethod 设置是否自动切换硬盘测试方法 |
| 219 | +func WithAutoChangeDiskMethod(enable bool) ConfigOption { |
| 220 | + return func(c *Config) { |
| 221 | + c.AutoChangeDiskMethod = enable |
| 222 | + } |
| 223 | +} |
| 224 | + |
| 225 | +// WithOnlyChinaTest 设置是否只进行国内测试 |
| 226 | +func WithOnlyChinaTest(enable bool) ConfigOption { |
| 227 | + return func(c *Config) { |
| 228 | + c.OnlyChinaTest = enable |
| 229 | + } |
| 230 | +} |
| 231 | + |
| 232 | +// WithMenuMode 设置是否启用菜单模式 |
| 233 | +func WithMenuMode(enable bool) ConfigOption { |
| 234 | + return func(c *Config) { |
| 235 | + c.MenuMode = enable |
| 236 | + } |
| 237 | +} |
| 238 | + |
| 239 | +// WithOnlyIpInfoCheck 设置是否只进行IP信息检测 |
| 240 | +func WithOnlyIpInfoCheck(enable bool) ConfigOption { |
| 241 | + return func(c *Config) { |
| 242 | + c.OnlyIpInfoCheck = enable |
| 243 | + } |
| 244 | +} |
| 245 | + |
| 246 | +// WithChoice 设置菜单选择 |
| 247 | +func WithChoice(choice string) ConfigOption { |
| 248 | + return func(c *Config) { |
| 249 | + c.Choice = choice |
| 250 | + } |
| 251 | +} |
| 252 | + |
| 253 | +// ApplyOptions 应用配置选项 |
| 254 | +func ApplyOptions(config *Config, options ...ConfigOption) *Config { |
| 255 | + for _, opt := range options { |
| 256 | + opt(config) |
| 257 | + } |
| 258 | + return config |
| 259 | +} |
0 commit comments