feat: support geosite attr (#98)

This commit is contained in:
mzz
2023-05-27 23:58:50 +08:00
committed by GitHub
parent 9e20a7fff6
commit 2a8f8f9010
2 changed files with 16 additions and 0 deletions

View File

@ -167,11 +167,26 @@ func (o *DatReaderOptimizer) loadGeoSite(filename string, code string) (params [
return nil, err
}
o.Logger.Debugf("Read geosite \"%v:%v\" from %v", filename, code, filePath)
code, attr, _ := strings.Cut(code, "@")
geoSite, err := geodata.UnmarshalGeoSite(o.Logger, filePath, code)
if err != nil {
return nil, err
}
for _, item := range geoSite.Domain {
if attr != "" {
// Filter by attr.
attrHit := false
for _, itemAttr := range item.Attribute {
if strings.EqualFold(itemAttr.Key, attr) {
attrHit = true
break
}
}
if !attrHit {
continue
}
}
switch item.Type {
case geodata.Domain_Full:
// Full.