mirror of
https://github.com/v2fly/domain-list-community.git
synced 2025-12-17 16:10:04 +07:00
Chore: refine code (#3067)
This commit is contained in:
15
main.go
15
main.go
@@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"errors"
|
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@@ -107,7 +106,7 @@ func (l *ParsedList) toProto() (*router.GeoSite, error) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("unknown domain type: " + entry.Type)
|
return nil, fmt.Errorf("unknown domain type: %s", entry.Type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return site, nil
|
return site, nil
|
||||||
@@ -153,13 +152,13 @@ func parseDomain(domain string, entry *Entry) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return errors.New("Invalid format: " + domain)
|
return fmt.Errorf("invalid format: %s", domain)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseAttribute(attr string) (*router.Domain_Attribute, error) {
|
func parseAttribute(attr string) (*router.Domain_Attribute, error) {
|
||||||
var attribute router.Domain_Attribute
|
var attribute router.Domain_Attribute
|
||||||
if len(attr) == 0 || attr[0] != '@' {
|
if len(attr) == 0 || attr[0] != '@' {
|
||||||
return &attribute, errors.New("invalid attribute: " + attr)
|
return &attribute, fmt.Errorf("invalid attribute: %s", attr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trim attribute prefix `@` character
|
// Trim attribute prefix `@` character
|
||||||
@@ -172,7 +171,7 @@ func parseAttribute(attr string) (*router.Domain_Attribute, error) {
|
|||||||
attribute.Key = strings.ToLower(parts[0])
|
attribute.Key = strings.ToLower(parts[0])
|
||||||
intv, err := strconv.Atoi(parts[1])
|
intv, err := strconv.Atoi(parts[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &attribute, errors.New("invalid attribute: " + attr + ": " + err.Error())
|
return &attribute, fmt.Errorf("invalid attribute: %s: %v", attr, err)
|
||||||
}
|
}
|
||||||
attribute.TypedValue = &router.Domain_Attribute_IntValue{IntValue: int64(intv)}
|
attribute.TypedValue = &router.Domain_Attribute_IntValue{IntValue: int64(intv)}
|
||||||
}
|
}
|
||||||
@@ -185,7 +184,7 @@ func parseEntry(line string) (Entry, error) {
|
|||||||
|
|
||||||
var entry Entry
|
var entry Entry
|
||||||
if len(parts) == 0 {
|
if len(parts) == 0 {
|
||||||
return entry, errors.New("empty entry")
|
return entry, fmt.Errorf("empty entry")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := parseDomain(parts[0], &entry); err != nil {
|
if err := parseDomain(parts[0], &entry); err != nil {
|
||||||
@@ -291,7 +290,7 @@ func ParseList(list *List, ref map[string]*List) (*ParsedList, error) {
|
|||||||
|
|
||||||
refList := ref[refName]
|
refList := ref[refName]
|
||||||
if refList == nil {
|
if refList == nil {
|
||||||
return nil, errors.New(entry.Value + " not found.")
|
return nil, fmt.Errorf("list not found: %s", entry.Value)
|
||||||
}
|
}
|
||||||
attrEntrys := createIncludeAttrEntrys(refList, attr)
|
attrEntrys := createIncludeAttrEntrys(refList, attr)
|
||||||
if len(attrEntrys) != 0 {
|
if len(attrEntrys) != 0 {
|
||||||
@@ -306,7 +305,7 @@ func ParseList(list *List, ref map[string]*List) (*ParsedList, error) {
|
|||||||
pl.Inclusion[InclusionName] = true
|
pl.Inclusion[InclusionName] = true
|
||||||
refList := ref[refName]
|
refList := ref[refName]
|
||||||
if refList == nil {
|
if refList == nil {
|
||||||
return nil, errors.New(entry.Value + " not found.")
|
return nil, fmt.Errorf("list not found: %s", entry.Value)
|
||||||
}
|
}
|
||||||
newEntryList = append(newEntryList, refList.Entry...)
|
newEntryList = append(newEntryList, refList.Entry...)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user