mirror of
https://github.com/v2fly/domain-list-community.git
synced 2025-12-31 23:07:30 +07:00
Refactor: promote refMap
This commit is contained in:
19
main.go
19
main.go
@@ -35,6 +35,10 @@ var (
|
||||
AttrChecker = regexp.MustCompile(`^[a-z0-9!-]+$`)
|
||||
)
|
||||
|
||||
var (
|
||||
refMap = make(map[string]*List)
|
||||
)
|
||||
|
||||
type Entry struct {
|
||||
Type string
|
||||
Value string
|
||||
@@ -205,12 +209,12 @@ func Load(path string) (*List, error) {
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func ParseList(list *List, ref map[string]*List) (*ParsedList, error) {
|
||||
func ParseList(refList *List) (*ParsedList, error) {
|
||||
pl := &ParsedList{
|
||||
Name: list.Name,
|
||||
Name: refList.Name,
|
||||
Inclusion: make(map[string]bool),
|
||||
}
|
||||
entryList := list.Entry
|
||||
entryList := refList.Entry
|
||||
for {
|
||||
newEntryList := make([]Entry, 0, len(entryList))
|
||||
hasInclude := false
|
||||
@@ -221,7 +225,7 @@ func ParseList(list *List, ref map[string]*List) (*ParsedList, error) {
|
||||
continue
|
||||
}
|
||||
pl.Inclusion[refName] = true
|
||||
refList := ref[refName]
|
||||
refList := refMap[refName]
|
||||
if refList == nil {
|
||||
return nil, fmt.Errorf("list not found: %s", entry.Value)
|
||||
}
|
||||
@@ -247,7 +251,6 @@ func main() {
|
||||
dir := *dataPath
|
||||
fmt.Println("Use domain lists in", dir)
|
||||
|
||||
ref := make(map[string]*List)
|
||||
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -259,7 +262,7 @@ func main() {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ref[list.Name] = list
|
||||
refMap[list.Name] = list
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
@@ -277,8 +280,8 @@ func main() {
|
||||
|
||||
protoList := new(router.GeoSiteList)
|
||||
var existList []string
|
||||
for _, list := range ref {
|
||||
pl, err := ParseList(list, ref)
|
||||
for _, refList := range refMap {
|
||||
pl, err := ParseList(refList)
|
||||
if err != nil {
|
||||
fmt.Println("Failed:", err)
|
||||
os.Exit(1)
|
||||
|
||||
Reference in New Issue
Block a user