diff --git a/internal/caches/list_file_db.go b/internal/caches/list_file_db.go index 8388f2a..9bd2c64 100644 --- a/internal/caches/list_file_db.go +++ b/internal/caches/list_file_db.go @@ -662,7 +662,7 @@ func (this *FileListDB) shouldRecover() bool { var errString = "" var shouldRecover = false if result.Next() { - err = result.Scan(&errString) + _ = result.Scan(&errString) if strings.TrimSpace(errString) != "ok" { shouldRecover = true } diff --git a/internal/caches/list_file_db_test.go b/internal/caches/list_file_db_test.go index a755f89..bd7f424 100644 --- a/internal/caches/list_file_db_test.go +++ b/internal/caches/list_file_db_test.go @@ -101,6 +101,9 @@ func TestFileListDB_CleanMatchPrefix(t *testing.T) { } err = db.Init() + if err != nil { + t.Fatal(err) + } err = db.CleanMatchPrefix("https://*.goedge.cn/large-text") if err != nil { diff --git a/internal/caches/manager.go b/internal/caches/manager.go index ee27295..a4cde69 100644 --- a/internal/caches/manager.go +++ b/internal/caches/manager.go @@ -148,8 +148,7 @@ func (this *Manager) FindPolicy(policyId int64) *serverconfigs.HTTPCachePolicy { this.locker.RLock() defer this.locker.RUnlock() - p, _ := this.policyMap[policyId] - return p + return this.policyMap[policyId] } // FindStorageWithPolicy 根据策略ID查找存储 @@ -157,8 +156,7 @@ func (this *Manager) FindStorageWithPolicy(policyId int64) StorageInterface { this.locker.RLock() defer this.locker.RUnlock() - storage, _ := this.storageMap[policyId] - return storage + return this.storageMap[policyId] } // NewStorageWithPolicy 根据策略获取存储对象 diff --git a/internal/caches/storage_file.go b/internal/caches/storage_file.go index d8cc5f3..56b418c 100644 --- a/internal/caches/storage_file.go +++ b/internal/caches/storage_file.go @@ -1276,13 +1276,6 @@ func (this *FileStorage) increaseHit(key string, hash string, reader Reader) { this.hotMapLocker.Lock() hotItem, ok := this.hotMap[key] - // 限制热点数据存活时间 - var unixTime = time.Now().Unix() - var expiresAt = reader.ExpiresAt() - if expiresAt <= 0 || expiresAt > unixTime+HotItemLifeSeconds { - expiresAt = unixTime + HotItemLifeSeconds - } - if ok { hotItem.Hits++ } else if len(this.hotMap) < HotItemSize { // 控制数量 diff --git a/internal/caches/utils_partial.go b/internal/caches/utils_partial.go index 7ae8f99..70f7f10 100644 --- a/internal/caches/utils_partial.go +++ b/internal/caches/utils_partial.go @@ -8,7 +8,7 @@ import "strings" func partialRangesFilePath(path string) string { // ranges路径 var dotIndex = strings.LastIndex(path, ".") - var rangePath = "" + var rangePath string if dotIndex < 0 { rangePath = path + "@ranges.cache" } else { diff --git a/internal/encrypt/method_aes_128_cfb_test.go b/internal/encrypt/method_aes_128_cfb_test.go index 9e1b8f7..d0e9d33 100644 --- a/internal/encrypt/method_aes_128_cfb_test.go +++ b/internal/encrypt/method_aes_128_cfb_test.go @@ -19,7 +19,6 @@ func TestAES128CFBMethod_Encrypt(t *testing.T) { dst = dst[:len(src)] t.Log("dst:", string(dst)) - src = make([]byte, len(src)) src, err = method.Decrypt(dst) if err != nil { t.Fatal(err) @@ -64,7 +63,6 @@ func TestAES128CFBMethod_Encrypt2(t *testing.T) { for _, dst := range sources { dst2 := append([]byte{}, dst...) - src2 := make([]byte, len(dst2)) src2, err := method.Decrypt(dst2) if err != nil { t.Fatal(err) diff --git a/internal/iplibrary/action_ipset.go b/internal/iplibrary/action_ipset.go index 4629a48..7169893 100644 --- a/internal/iplibrary/action_ipset.go +++ b/internal/iplibrary/action_ipset.go @@ -283,7 +283,7 @@ func (this *IPSetAction) runActionSingleIP(action string, listType IPListType, i return nil } - var listName = "" + var listName string var isIPv6 = strings.Contains(item.IpFrom, ":") switch listType { diff --git a/internal/iplibrary/action_manager.go b/internal/iplibrary/action_manager.go index 86e6a51..879dfe1 100644 --- a/internal/iplibrary/action_manager.go +++ b/internal/iplibrary/action_manager.go @@ -102,7 +102,7 @@ func (this *ActionManager) UpdateActions(actions []*firewallconfigs.FirewallActi continue } - instances, _ := this.eventMap[action.EventLevel] + var instances = this.eventMap[action.EventLevel] instances = append(instances, instance) this.eventMap[action.EventLevel] = instances } diff --git a/internal/iplibrary/manager_ip_list.go b/internal/iplibrary/manager_ip_list.go index 78f5ded..55d5de6 100644 --- a/internal/iplibrary/manager_ip_list.go +++ b/internal/iplibrary/manager_ip_list.go @@ -214,7 +214,7 @@ func (this *IPListManager) fetch() (hasNext bool, err error) { func (this *IPListManager) FindList(listId int64) *IPList { this.locker.Lock() - list, _ := this.listMap[listId] + var list = this.listMap[listId] this.locker.Unlock() return list } diff --git a/internal/nodes/client_listener.go b/internal/nodes/client_listener.go index a76ba63..53f7368 100644 --- a/internal/nodes/client_listener.go +++ b/internal/nodes/client_listener.go @@ -48,7 +48,7 @@ func (this *ClientListener) Accept() (net.Conn, error) { firewalls.DropTemporaryTo(ip, expiresAt) } else { if !waf.SharedIPWhiteList.Contains(waf.IPTypeAll, firewallconfigs.FirewallScopeGlobal, 0, ip) { - var ok = false + var ok bool expiresAt, ok = waf.SharedIPBlackList.ContainsExpires(waf.IPTypeAll, firewallconfigs.FirewallScopeGlobal, 0, ip) if ok { canGoNext = false diff --git a/internal/nodes/http_request_host_redirect.go b/internal/nodes/http_request_host_redirect.go index 7d47710..2103ae2 100644 --- a/internal/nodes/http_request_host_redirect.go +++ b/internal/nodes/http_request_host_redirect.go @@ -34,7 +34,7 @@ func (this *HTTPRequest) doHostRedirect() (blocked bool) { } } - var fullURL = "" + var fullURL string if u.BeforeHasQuery() { fullURL = this.URL() } else { @@ -194,7 +194,7 @@ func (this *HTTPRequest) doHostRedirect() (blocked bool) { return false } - var containsPort = false + var containsPort bool if u.PortsAll { containsPort = true } else { diff --git a/internal/nodes/http_writer.go b/internal/nodes/http_writer.go index 8d00744..b39c6d1 100644 --- a/internal/nodes/http_writer.go +++ b/internal/nodes/http_writer.go @@ -731,7 +731,6 @@ func (this *HTTPWriter) PrepareCompression(resp *http.Response, size int64) { } // compression writer - var err error = nil compressionWriter, err := compressions.NewWriter(this.writer, compressionType, int(this.compressionConfig.Level)) if err != nil { remotelogs.Error("HTTP_WRITER", err.Error()) diff --git a/internal/re/regexp_test.go b/internal/re/regexp_test.go index 695e0e9..d2cef6d 100644 --- a/internal/re/regexp_test.go +++ b/internal/re/regexp_test.go @@ -149,7 +149,7 @@ func BenchmarkRegexp_MatchString(b *testing.B) { } func BenchmarkRegexp_MatchString2(b *testing.B) { - var r = regexp.MustCompile("(?i)(onmouseover|onmousemove|onmousedown|onmouseup|onerror|onload|onclick|ondblclick|onkeydown|onkeyup|onkeypress)(\\s|%09|%0A|(\\+|%20))*(=|%3D)") + var r = regexp.MustCompile(`(?i)(onmouseover|onmousemove|onmousedown|onmouseup|onerror|onload|onclick|ondblclick|onkeydown|onkeyup|onkeypress)(\s|%09|%0A|(\+|%20))*(=|%3D)`) b.ResetTimer() for i := 0; i < b.N; i++ { diff --git a/internal/ttlcache/cache.go b/internal/ttlcache/cache.go index f6a0e71..c709ae6 100644 --- a/internal/ttlcache/cache.go +++ b/internal/ttlcache/cache.go @@ -13,7 +13,6 @@ var SharedCache = NewBigCache() // // Piece1 | Piece2 | Piece3 | ... // [ Item1, Item2, ... ] | ... -// type Cache struct { isDestroyed bool pieces []*Piece @@ -123,19 +122,11 @@ func (this *Cache) Read(key string) (item *Item) { return this.pieces[uint64Key%this.countPieces].Read(uint64Key) } -func (this *Cache) readIntKey(key uint64) (value *Item) { - return this.pieces[key%this.countPieces].Read(key) -} - func (this *Cache) Delete(key string) { var uint64Key = HashKey([]byte(key)) this.pieces[uint64Key%this.countPieces].Delete(uint64Key) } -func (this *Cache) deleteIntKey(key uint64) { - this.pieces[key%this.countPieces].Delete(key) -} - func (this *Cache) Count() (count int) { for _, piece := range this.pieces { count += piece.Count() diff --git a/internal/utils/ip.go b/internal/utils/ip.go index 2f9c300..b5f9ba4 100644 --- a/internal/utils/ip.go +++ b/internal/utils/ip.go @@ -34,10 +34,7 @@ func IsLocalIP(ipString string) bool { // IPv6 if strings.Contains(ipString, ":") { - if ip.String() == "::1" { - return true - } - return false + return ip.String() == "::1" } // IPv4 diff --git a/internal/utils/sync/map_int.go b/internal/utils/sync/map_int.go index f89ae8d..0f358f3 100644 --- a/internal/utils/sync/map_int.go +++ b/internal/utils/sync/map_int.go @@ -72,7 +72,7 @@ func (this *IntMap[K, V]) Has(k K) bool { func (this *IntMap[K, V]) Get(k K) (value V) { var index = this.index(k) this.lockers[index].RLock() - value, _ = this.m[index][k] + value = this.m[index][k] this.lockers[index].RUnlock() return } diff --git a/internal/utils/system_1.19.go b/internal/utils/system_1.19.go index 5a267b2..30bfccd 100644 --- a/internal/utils/system_1.19.go +++ b/internal/utils/system_1.19.go @@ -12,7 +12,7 @@ func setMaxMemory(memoryGB int) { if memoryGB <= 0 { memoryGB = 1 } - var maxMemoryBytes int64 = 0 + var maxMemoryBytes int64 if memoryGB > 10 { maxMemoryBytes = int64(memoryGB-2) << 30 // 超过10G内存的允许剩余2G内存 } else { diff --git a/internal/utils/writers/writer_rate_limit.go b/internal/utils/writers/writer_rate_limit.go index 8cb4fe0..101a196 100644 --- a/internal/utils/writers/writer_rate_limit.go +++ b/internal/utils/writers/writer_rate_limit.go @@ -85,7 +85,7 @@ func (this *RateLimitWriter) write(p []byte) (n int, err error) { this.written += n if this.written >= this.rateBytes { - var duration = 1*time.Second - time.Now().Sub(this.before) + var duration = 1*time.Second - time.Since(this.before) if duration > 0 { time.Sleep(duration) } diff --git a/internal/waf/captcha_validator.go b/internal/waf/captcha_validator.go index f90bd92..e327af4 100644 --- a/internal/waf/captcha_validator.go +++ b/internal/waf/captcha_validator.go @@ -108,10 +108,10 @@ func (this *CaptchaValidator) show(actionConfig *CaptchaAction, req requests.Req lang = "en-US" } - var msgTitle = "" - var msgPrompt = "" - var msgButtonTitle = "" - var msgRequestId = "" + var msgTitle string + var msgPrompt string + var msgButtonTitle string + var msgRequestId string switch lang { case "en-US": diff --git a/internal/waf/checkpoints/cc.go b/internal/waf/checkpoints/cc.go index 1399133..b2e37db 100644 --- a/internal/waf/checkpoints/cc.go +++ b/internal/waf/checkpoints/cc.go @@ -40,14 +40,9 @@ func (this *CCCheckpoint) RequestValue(req requests.Request, param string, optio period = 7 * 86400 } - v, _ := options["userType"] - userType := types.String(v) - - v, _ = options["userField"] - userField := types.String(v) - - v, _ = options["userIndex"] - userIndex := types.Int(v) + var userType = types.String(options["userType"]) + var userField = types.String(options["userField"]) + var userIndex = types.Int(options["userIndex"]) if param == "requests" { // requests var key = "" diff --git a/internal/waf/rule.go b/internal/waf/rule.go index 976f9ab..6bed948 100644 --- a/internal/waf/rule.go +++ b/internal/waf/rule.go @@ -23,7 +23,7 @@ import ( "strings" ) -var singleParamRegexp = regexp.MustCompile("^\\${[\\w.-]+}$") +var singleParamRegexp = regexp.MustCompile(`^\${[\w.-]+}$`) // Rule type Rule struct { diff --git a/internal/waf/waf_manager.go b/internal/waf/waf_manager.go index a67d874..59eac4c 100644 --- a/internal/waf/waf_manager.go +++ b/internal/waf/waf_manager.go @@ -45,7 +45,7 @@ func (this *WAFManager) UpdatePolicies(policies []*firewallconfigs.HTTPFirewallP // FindWAF 查找WAF func (this *WAFManager) FindWAF(policyId int64) *WAF { this.locker.RLock() - w, _ := this.mapping[policyId] + var w = this.mapping[policyId] this.locker.RUnlock() return w }