depot/third_party/nixpkgs/pkgs/data/misc/sing-geosite/main.go
Default email 587713944a Project import generated by Copybara.
GitOrigin-RevId: 6143fc5eeb9c4f00163267708e26191d1e918932
2024-04-21 17:54:59 +02:00

52 lines
1.3 KiB
Go

func main() {
outputFile, err := os.Create("geosite.db")
if err != nil {
panic(err)
}
defer outputFile.Close()
vData, err := ioutil.ReadFile("@geosite_data@")
if err != nil {
panic(err)
}
domainMap, err := parse(vData)
if err != nil {
panic(err)
}
err = geosite.Write(outputFile, domainMap)
if err != nil {
panic(err)
}
ruleSetOutput := "rule-set"
err = os.MkdirAll(ruleSetOutput, 0o755)
if err != nil {
panic(err)
}
for code, domains := range domainMap {
var headlessRule option.DefaultHeadlessRule
defaultRule := geosite.Compile(domains)
headlessRule.Domain = defaultRule.Domain
headlessRule.DomainSuffix = defaultRule.DomainSuffix
headlessRule.DomainKeyword = defaultRule.DomainKeyword
headlessRule.DomainRegex = defaultRule.DomainRegex
var plainRuleSet option.PlainRuleSet
plainRuleSet.Rules = []option.HeadlessRule{
{
Type: C.RuleTypeDefault,
DefaultOptions: headlessRule,
},
}
srsPath, _ := filepath.Abs(filepath.Join(ruleSetOutput, "geosite-"+code+".srs"))
os.Stderr.WriteString("write " + srsPath + "\n")
outputRuleSet, err := os.Create(srsPath)
if err != nil {
panic(err)
}
err = srs.Write(outputRuleSet, plainRuleSet)
if err != nil {
outputRuleSet.Close()
panic(err)
}
outputRuleSet.Close()
}
}