mirror of
https://github.com/v2fly/domain-list-community.git
synced 2026-01-07 07:13:57 +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!-]+$`)
|
AttrChecker = regexp.MustCompile(`^[a-z0-9!-]+$`)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
refMap = make(map[string]*List)
|
||||||
|
)
|
||||||
|
|
||||||
type Entry struct {
|
type Entry struct {
|
||||||
Type string
|
Type string
|
||||||
Value string
|
Value string
|
||||||
@@ -191,12 +195,12 @@ func Load(path string) (*List, error) {
|
|||||||
return list, nil
|
return list, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseList(list *List, ref map[string]*List) (*ParsedList, error) {
|
func ParseList(refList *List) (*ParsedList, error) {
|
||||||
pl := &ParsedList{
|
pl := &ParsedList{
|
||||||
Name: list.Name,
|
Name: refList.Name,
|
||||||
Inclusion: make(map[string]bool),
|
Inclusion: make(map[string]bool),
|
||||||
}
|
}
|
||||||
entryList := list.Entry
|
entryList := refList.Entry
|
||||||
for {
|
for {
|
||||||
newEntryList := make([]Entry, 0, len(entryList))
|
newEntryList := make([]Entry, 0, len(entryList))
|
||||||
hasInclude := false
|
hasInclude := false
|
||||||
@@ -207,7 +211,7 @@ func ParseList(list *List, ref map[string]*List) (*ParsedList, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
pl.Inclusion[refName] = true
|
pl.Inclusion[refName] = true
|
||||||
refList := ref[refName]
|
refList := refMap[refName]
|
||||||
if refList == nil {
|
if refList == nil {
|
||||||
return nil, fmt.Errorf("list not found: %s", entry.Value)
|
return nil, fmt.Errorf("list not found: %s", entry.Value)
|
||||||
}
|
}
|
||||||
@@ -233,7 +237,6 @@ func main() {
|
|||||||
dir := *dataPath
|
dir := *dataPath
|
||||||
fmt.Println("Use domain lists in", dir)
|
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 {
|
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -245,7 +248,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
ref[list.Name] = list
|
refMap[list.Name] = list
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -263,8 +266,8 @@ func main() {
|
|||||||
|
|
||||||
protoList := new(router.GeoSiteList)
|
protoList := new(router.GeoSiteList)
|
||||||
var existList []string
|
var existList []string
|
||||||
for _, list := range ref {
|
for _, refList := range refMap {
|
||||||
pl, err := ParseList(list, ref)
|
pl, err := ParseList(refList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Failed:", err)
|
fmt.Println("Failed:", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user