chore: change ACL iso field to country

This commit is contained in:
yusing 2025-04-25 13:25:45 +08:00
parent 4410637f8b
commit 1e790be70c

View file

@ -14,16 +14,16 @@ const (
MatcherTypeIP = "ip" MatcherTypeIP = "ip"
MatcherTypeCIDR = "cidr" MatcherTypeCIDR = "cidr"
MatcherTypeTimeZone = "tz" MatcherTypeTimeZone = "tz"
MatcherTypeISO = "iso" MatcherTypeCountry = "country"
) )
var errMatcherFormat = gperr.Multiline().AddLines( var errMatcherFormat = gperr.Multiline().AddLines(
"invalid matcher format, expect {type}:{value}", "invalid matcher format, expect {type}:{value}",
"Available types: ip|cidr|tz|iso", "Available types: ip|cidr|tz|country",
"ip:127.0.0.1", "ip:127.0.0.1",
"cidr:127.0.0.0/8", "cidr:127.0.0.0/8",
"tz:Asia/Shanghai", "tz:Asia/Shanghai",
"iso:GB", "country:GB",
) )
var ( var (
errSyntax = gperr.New("syntax error") errSyntax = gperr.New("syntax error")
@ -56,11 +56,11 @@ func (cfg *Config) parseMatcher(s string) (matcher, gperr.Error) {
return nil, errMaxMindNotConfigured return nil, errMaxMindNotConfigured
} }
return cfg.MaxMind.matchTimeZone(parts[1]), nil return cfg.MaxMind.matchTimeZone(parts[1]), nil
case MatcherTypeISO: case MatcherTypeCountry:
if cfg.MaxMind == nil { if cfg.MaxMind == nil {
return nil, errMaxMindNotConfigured return nil, errMaxMindNotConfigured
} }
return cfg.MaxMind.matchISO(parts[1]), nil return cfg.MaxMind.matchISOCode(parts[1]), nil
default: default:
return nil, errSyntax return nil, errSyntax
} }
@ -88,7 +88,7 @@ func (cfg *MaxMindConfig) matchTimeZone(tz string) matcher {
} }
} }
func (cfg *MaxMindConfig) matchISO(iso string) matcher { func (cfg *MaxMindConfig) matchISOCode(iso string) matcher {
return func(ip *acl.IPInfo) bool { return func(ip *acl.IPInfo) bool {
city, ok := cfg.lookupCity(ip) city, ok := cfg.lookupCity(ip)
if !ok { if !ok {