diff --git a/internal/caches/list_file_db.go b/internal/caches/list_file_db.go index 527805a..8388f2a 100644 --- a/internal/caches/list_file_db.go +++ b/internal/caches/list_file_db.go @@ -661,12 +661,11 @@ func (this *FileListDB) shouldRecover() bool { } var errString = "" var shouldRecover = false - for result.Next() { + if result.Next() { err = result.Scan(&errString) if strings.TrimSpace(errString) != "ok" { shouldRecover = true } - break } _ = result.Close() return shouldRecover diff --git a/internal/caches/list_file_db_test.go b/internal/caches/list_file_db_test.go index 73a8f8d..a755f89 100644 --- a/internal/caches/list_file_db_test.go +++ b/internal/caches/list_file_db_test.go @@ -47,6 +47,10 @@ func TestFileListDB_IncreaseHitAsync(t *testing.T) { } err = db.Init() + if err != nil { + t.Fatal(err) + } + err = db.IncreaseHitAsync("4598e5231ba47d6ec7aa9ea640ff2eaf") if err != nil { t.Fatal(err) @@ -69,6 +73,9 @@ func TestFileListDB_CleanMatchKey(t *testing.T) { } err = db.Init() + if err != nil { + t.Fatal(err) + } err = db.CleanMatchKey("https://*.goedge.cn/large-text") if err != nil { diff --git a/internal/caches/utils_test.go b/internal/caches/utils_test.go index 836c6b9..4da2e64 100644 --- a/internal/caches/utils_test.go +++ b/internal/caches/utils_test.go @@ -29,7 +29,7 @@ func TestParseHost(t *testing.T) { func TestUintString(t *testing.T) { t.Log(strconv.FormatUint(xxhash.Sum64String("https://goedge.cn/"), 10)) t.Log(strconv.FormatUint(123456789, 10)) - t.Log(fmt.Sprintf("%d", 1234567890123)) + t.Logf("%d", 1234567890123) } func BenchmarkUint_String(b *testing.B) { diff --git a/internal/nodes/http_access_log_queue_test.go b/internal/nodes/http_access_log_queue_test.go index a4ba9a9..0e1dcdc 100644 --- a/internal/nodes/http_access_log_queue_test.go +++ b/internal/nodes/http_access_log_queue_test.go @@ -122,6 +122,7 @@ func TestHTTPAccessLogQueue_Memory(t *testing.T) { } runtime.GC() + _ = accessLogs // will not release automatically func() { @@ -131,6 +132,7 @@ func TestHTTPAccessLogQueue_Memory(t *testing.T) { RequestPath: "https://goedge.cn/hello/world", }) } + _ = accessLogs1 }() time.Sleep(5 * time.Second) diff --git a/internal/nodes/http_request_fastcgi.go b/internal/nodes/http_request_fastcgi.go index b1057ed..f591060 100644 --- a/internal/nodes/http_request_fastcgi.go +++ b/internal/nodes/http_request_fastcgi.go @@ -111,7 +111,7 @@ func (this *HTTPRequest) doFastcgi() (shouldStop bool) { // 处理SCRIPT_FILENAME scriptPath := env.GetString("SCRIPT_FILENAME") - if len(scriptPath) > 0 && (strings.Index(scriptPath, "/") < 0 && strings.Index(scriptPath, "\\") < 0) { + if len(scriptPath) > 0 && !strings.Contains(scriptPath, "/") && !strings.Contains(scriptPath, "\\") { env["SCRIPT_FILENAME"] = env.GetString("DOCUMENT_ROOT") + Tea.DS + scriptPath } scriptFilename := filepath.Base(this.RawReq.URL.Path) diff --git a/internal/nodes/listener_http.go b/internal/nodes/listener_http.go index d97ed9c..e22f1eb 100644 --- a/internal/nodes/listener_http.go +++ b/internal/nodes/listener_http.go @@ -210,7 +210,7 @@ func (this *HTTPListener) ServeHTTP(rawWriter http.ResponseWriter, rawReq *http. // 检查host是否为IP func (this *HTTPListener) isIP(host string) bool { // IPv6 - if strings.Index(host, "[") > -1 { + if strings.Contains(host, "[") { return true } diff --git a/internal/stats/bandwidth_stat_manager_test.go b/internal/stats/bandwidth_stat_manager_test.go index 6b63dc9..665d6c0 100644 --- a/internal/stats/bandwidth_stat_manager_test.go +++ b/internal/stats/bandwidth_stat_manager_test.go @@ -68,6 +68,7 @@ func BenchmarkBandwidthStatManager_Slice(b *testing.B) { NodeRegionId: 1, }) } + _ = pbStats } } @@ -80,6 +81,7 @@ func BenchmarkBandwidthStatManager_Slice2(b *testing.B) { var stat = &stats.BandwidthStat{} statsSlice = append(statsSlice, stat) } + _ = statsSlice } } diff --git a/internal/utils/expires/list_test.go b/internal/utils/expires/list_test.go index bc39ac4..dab6a7c 100644 --- a/internal/utils/expires/list_test.go +++ b/internal/utils/expires/list_test.go @@ -153,7 +153,7 @@ func TestList_Map_Performance(t *testing.T) { for i := 0; i < 100_000; i++ { delete(m, uint64(i)) } - t.Log(time.Now().Sub(now)) + t.Log(time.Since(now)) } { @@ -166,7 +166,7 @@ func TestList_Map_Performance(t *testing.T) { for i := 0; i < 100_000; i++ { delete(m, uint32(i)) } - t.Log(time.Now().Sub(now)) + t.Log(time.Since(now)) } } diff --git a/internal/utils/jsonutils/map_test.go b/internal/utils/jsonutils/map_test.go index 6bccfcf..2527f5e 100644 --- a/internal/utils/jsonutils/map_test.go +++ b/internal/utils/jsonutils/map_test.go @@ -36,9 +36,6 @@ func TestMapToObject(t *testing.T) { if err != nil { t.Fatal(err) } - if obj == nil { - t.Fatal("obj should not be nil") - } a.IsTrue(obj.B == 1024) a.IsTrue(obj.C == true) PrintT(obj, t) diff --git a/internal/utils/service.go b/internal/utils/service.go index 8da9146..2c86d81 100644 --- a/internal/utils/service.go +++ b/internal/utils/service.go @@ -11,7 +11,7 @@ import ( "sync" ) -// 服务管理器 +// ServiceManager 服务管理器 type ServiceManager struct { Name string Description string @@ -39,7 +39,7 @@ func (this *ServiceManager) setup() { this.onceLocker.Do(func() { logFile := files.NewFile(Tea.Root + "/logs/service.log") if logFile.Exists() { - logFile.Delete() + _ = logFile.Delete() } //logger @@ -53,7 +53,7 @@ func (this *ServiceManager) setup() { }) } -// 记录普通日志 +// Log 记录普通日志 func (this *ServiceManager) Log(msg string) { this.setup() if this.logger == nil { @@ -62,7 +62,7 @@ func (this *ServiceManager) Log(msg string) { this.logger.Println("[info]" + msg) } -// 记录错误日志 +// LogError 记录错误日志 func (this *ServiceManager) LogError(msg string) { this.setup() if this.logger == nil { @@ -71,7 +71,7 @@ func (this *ServiceManager) LogError(msg string) { this.logger.Println("[error]" + msg) } -// 关闭 +// Close 关闭 func (this *ServiceManager) Close() error { if this.fp != nil { return this.fp.Close() @@ -100,7 +100,7 @@ func (this *ServiceManager) resetRoot() { Tea.SetTmpDir(Tea.Root + Tea.DS + "web" + Tea.DS + "tmp") } -// 保持命令行窗口是打开的 +// PauseWindow 保持命令行窗口是打开的 func (this *ServiceManager) PauseWindow() { if runtime.GOOS != "windows" { return diff --git a/internal/waf/checkpoints/cc.go b/internal/waf/checkpoints/cc.go index f9160ed..1399133 100644 --- a/internal/waf/checkpoints/cc.go +++ b/internal/waf/checkpoints/cc.go @@ -133,7 +133,7 @@ func (this *CCCheckpoint) Options() []OptionInterface { option.Size = 8 option.MaxLength = 8 option.Validate = func(value string) (ok bool, message string) { - if regexp.MustCompile("^\\d+$").MatchString(value) { + if regexp.MustCompile(`^\d+$`).MatchString(value) { ok = true return } diff --git a/internal/waf/checkpoints/cc2.go b/internal/waf/checkpoints/cc2.go index 7be20e9..2124a22 100644 --- a/internal/waf/checkpoints/cc2.go +++ b/internal/waf/checkpoints/cc2.go @@ -57,10 +57,10 @@ func (this *CC2Checkpoint) RequestValue(req requests.Request, param string, opti period = 7 * 86400 } - var threshold = options.GetInt64("threshold") + /**var threshold = options.GetInt64("threshold") if threshold <= 0 { threshold = 1000 - } + }**/ var ignoreCommonFiles = options.GetBool("ignoreCommonFiles") if ignoreCommonFiles {