mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 12:42:34 +02:00
chore: change ACL iso field to country
This commit is contained in:
parent
4410637f8b
commit
1e790be70c
1 changed files with 6 additions and 6 deletions
|
@ -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 {
|
||||||
|
|
Loading…
Add table
Reference in a new issue