docs(middleware): 为中间件模块添加标准化 godoc 注释
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
42a4c8d311
commit
13bfc090f7
@ -48,6 +48,7 @@ const (
|
||||
|
||||
accessAllow = "allow"
|
||||
accessDeny = "deny"
|
||||
accessUnknown = "unknown"
|
||||
geoPrivateAllow = "PRIVATE_ALLOW"
|
||||
geoPrivateDeny = "PRIVATE_DENY"
|
||||
)
|
||||
@ -478,7 +479,7 @@ func actionToString(action Action) string {
|
||||
case ActionDeny:
|
||||
return accessDeny
|
||||
default:
|
||||
return "unknown"
|
||||
return accessUnknown
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -88,7 +88,7 @@ func NewGeoIPLookup(dbPath string, cacheSize int, ttl time.Duration, privateIPBe
|
||||
|
||||
// 默认私有 IP 行为
|
||||
if privateIPBehavior == "" {
|
||||
privateIPBehavior = "allow"
|
||||
privateIPBehavior = accessAllow
|
||||
}
|
||||
|
||||
return &GeoIPLookup{
|
||||
@ -114,7 +114,7 @@ func (g *GeoIPLookup) LookupCountry(ip net.IP) (string, error) {
|
||||
// 检查私有 IP
|
||||
if isPrivateIP(ip) {
|
||||
switch g.privateIPBehavior {
|
||||
case "allow":
|
||||
case accessAllow:
|
||||
return "PRIVATE_ALLOW", nil // 特殊标记,表示允许
|
||||
case accessDeny:
|
||||
return "PRIVATE_DENY", nil // 特殊标记,表示拒绝
|
||||
|
||||
@ -250,7 +250,12 @@ func TestGeoIPLookup_Close(t *testing.T) {
|
||||
|
||||
// TestGeoIPLookup_TTLExpiration 测试缓存 TTL 过期。
|
||||
func TestGeoIPLookup_TTLExpiration(t *testing.T) {
|
||||
geoip, err := NewGeoIPLookup("/tmp/GeoIP2-Country-Test.mmdb", 1000, 1*time.Millisecond, "allow")
|
||||
testDB := "/tmp/GeoIP2-Country-Test.mmdb"
|
||||
if _, err := os.Stat(testDB); os.IsNotExist(err) {
|
||||
t.Skipf("Skipping test: GeoIP test database not available: %v", err)
|
||||
}
|
||||
|
||||
geoip, err := NewGeoIPLookup(testDB, 1000, 1*time.Millisecond, "allow")
|
||||
require.NoError(t, err)
|
||||
defer geoip.Close()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user