Skip to content

Commit

Permalink
add option to skip generate measure
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxkad committed Dec 14, 2023
1 parent 1a82e15 commit 3171919
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
1 change: 1 addition & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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, // 劫持代理监听的端口
Expand Down
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
42 changes: 23 additions & 19 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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",
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3171919

Please sign in to comment.