diff --git a/README.MD b/README.MD index 922c5ac5..a0072454 100644 --- a/README.MD +++ b/README.MD @@ -63,6 +63,7 @@ // 特殊要求: 重定向到 OSS "use_oss": false, // 是否启用本功能 "oss_redirect_base": "https://oss.example.com/base/paths", + "oss_skip_measure_gen": false, // 跳过生成measure文件夹 // 特殊要求: 劫持 bmclapi 以加速同一局域网请求 "hijack": false, // 是否启动 bmclapi 劫持代理 "hijack_port": 8090, // 劫持代理监听的端口 diff --git a/config.json b/config.json index fac7a3d2..f3f62e3e 100644 --- a/config.json +++ b/config.json @@ -9,6 +9,7 @@ "cluster_secret": "${CLUSTER_SECRET}", "use_oss": false, "oss_redirect_base": "https://oss.example.com/base/paths", + "oss_skip_measure_gen": false, "hijack": false, "hijack_port": 8090, "anti_hijack_dns": "8.8.8.8:53" diff --git a/src/main.go b/src/main.go index c65fce55..6f5a445d 100644 --- a/src/main.go +++ b/src/main.go @@ -34,6 +34,7 @@ type Config struct { ClusterSecret string `json:"cluster_secret"` UseOss bool `json:"use_oss"` OssRedirectBase string `json:"oss_redirect_base"` + SkipMeasureGen bool `json:"oss_skip_measure_gen"` Hijack bool `json:"hijack"` HijackPort uint16 `json:"hijack_port"` AntiHijackDNS string `json:"anti_hijack_dns"` @@ -55,6 +56,7 @@ func readConfig() { ClusterSecret: "${CLUSTER_SECRET}", UseOss: false, OssRedirectBase: "https://oss.example.com/base/paths", + SkipMeasureGen: false, Hijack: false, HijackPort: 8090, AntiHijackDNS: "8.8.8.8:53", @@ -309,28 +311,30 @@ func createOssMirrorDir() { os.Exit(2) } } - logDebug("Creating measure files") - buf := make([]byte, 200 * 1024 * 1024) - for i := 1; i <= 200; i++ { - size := i * 1024 * 1024 - t := filepath.Join(measureDir, strconv.Itoa(i)) - if stat, err := os.Stat(t); err == nil { - x := stat.Size() - if x == (int64)(size) { - logDebug("Skipping", t) - continue + if !config.SkipMeasureGen { + logDebug("Creating measure files") + buf := make([]byte, 200*1024*1024) + for i := 1; i <= 200; i++ { + size := i * 1024 * 1024 + t := filepath.Join(measureDir, strconv.Itoa(i)) + if stat, err := os.Stat(t); err == nil { + x := stat.Size() + if x == (int64)(size) { + logDebug("Skipping", t) + continue + } + logDebugf("File [%d] size %d does not match %d", i, x, size) + } else { + logDebugf("Cannot get stat of %s: %v", t, err) + } + logDebug("Writing", t) + if err := os.WriteFile(t, buf[:size], 0644); err != nil { + logErrorf("Cannot create OSS mirror measure file %q: %v", t, err) + os.Exit(2) } - logDebugf("File [%d] size %d does not match %d", i, x, size) - }else{ - logDebugf("Cannot get stat of %s: %v", t, err) - } - logDebug("Writing", t) - if err := os.WriteFile(t, buf[:size], 0644); err != nil { - logErrorf("Cannot create OSS mirror measure file %q: %v", t, err) - os.Exit(2) } + logDebug("Measure files created") } - logDebug("Measure files created") } func assertOSS(size int) {