diff --git a/clash.go b/clash.go index 8e1fd87..5cd2998 100644 --- a/clash.go +++ b/clash.go @@ -10,7 +10,6 @@ import ( "github.com/metacubex/meta-rules-converter/output/sing" - "github.com/sagernet/sing-box/option" "github.com/spf13/cobra" "gopkg.in/yaml.v3" ) @@ -113,7 +112,7 @@ func convertClash(cmd *cobra.Command, args []string) error { for name, domain := range domainFull { os.MkdirAll(outDir+"/"+name, 0755) if len(domain) != 0 || len(domainSuffix[name]) != 0 || len(domainKeyword[name]) != 0 || len(domainRegex[name]) != 0 { - domainRule := []option.DefaultHeadlessRule{ + domainRule := []sing.DefaultHeadlessRule{ { Domain: domain, DomainKeyword: domainKeyword[name], @@ -124,7 +123,7 @@ func convertClash(cmd *cobra.Command, args []string) error { sing.SaveSingRuleSet(domainRule, outDir+"/"+name+"/domain") } if len(ipCIDR[name]) != 0 { - ipRule := []option.DefaultHeadlessRule{ + ipRule := []sing.DefaultHeadlessRule{ { IPCIDR: ipCIDR[name], }, @@ -132,7 +131,7 @@ func convertClash(cmd *cobra.Command, args []string) error { sing.SaveSingRuleSet(ipRule, outDir+"/"+name+"/ip") } if len(processName[name]) != 0 || len(packageName[name]) != 0 || len(processPath[name]) != 0 { - processRule := []option.DefaultHeadlessRule{ + processRule := []sing.DefaultHeadlessRule{ { ProcessName: processName[name], PackageName: packageName[name], @@ -142,14 +141,14 @@ func convertClash(cmd *cobra.Command, args []string) error { sing.SaveSingRuleSet(processRule, outDir+"/"+name+"/process") } if len(dstPort[name]) != 0 { - otherRule := []option.DefaultHeadlessRule{ + otherRule := []sing.DefaultHeadlessRule{ { Port: dstPort[name], }, } sing.SaveSingRuleSet(otherRule, outDir+"/"+name+"/other") } - classicalRule := []option.DefaultHeadlessRule{ + classicalRule := []sing.DefaultHeadlessRule{ { Domain: domainFull[name], DomainKeyword: domainKeyword[name], diff --git a/geoip.go b/geoip.go index f2f9c75..f4bcd70 100644 --- a/geoip.go +++ b/geoip.go @@ -14,7 +14,6 @@ import ( "gopkg.in/yaml.v3" "github.com/metacubex/mihomo/component/geodata/router" - "github.com/sagernet/sing-box/option" "github.com/spf13/cobra" ) @@ -109,11 +108,12 @@ func convertIP(cmd *cobra.Command, args []string) error { if err != nil { fmt.Println(code, " output err: ", err) } - err = os.WriteFile(outDir+"/"+code+".list", []byte(strings.Join(cidrs, "\n")), 0755) + ipcidrOut = []byte(strings.Join(cidrs, "\n")) + err = os.WriteFile(outDir+"/"+code+".list", ipcidrOut, 0755) if err != nil { fmt.Println(code, " output err: ", err) } - err = meta.SaveMetaRuleSet(ipcidrOut, "ipcidr", "yaml", outDir+"/"+code+".mrs") + err = meta.SaveMetaRuleSet(ipcidrOut, "ipcidr", "text", outDir+"/"+code+".mrs") if err != nil { fmt.Println(code, " output err: ", err) } @@ -130,15 +130,16 @@ func convertIP(cmd *cobra.Command, args []string) error { if err != nil { fmt.Println(code, " output err: ", err) } - err = os.WriteFile(outDir+"/classical/"+code+".list", []byte(strings.Join(cidrs, "\n")), 0755) + classicalOut = []byte(strings.Join(cidrs, "\n")) + err = os.WriteFile(outDir+"/classical/"+code+".list", classicalOut, 0755) if err != nil { fmt.Println(code, " output err: ", err) } - // meta.SaveMetaRuleSet(classicalOut, "classical", "yaml", outDir+"/classical/"+code+".mrs") + // meta.SaveMetaRuleSet(classicalOut, "classical", "text", outDir+"/classical/"+code+".mrs") } case "sing-box": for code, cidrs := range countryCIDRs { - ipcidrRule := []option.DefaultHeadlessRule{ + ipcidrRule := []sing.DefaultHeadlessRule{ { IPCIDR: cidrs, }, diff --git a/geosite.go b/geosite.go index 063042a..c939c4a 100644 --- a/geosite.go +++ b/geosite.go @@ -13,7 +13,6 @@ import ( "gopkg.in/yaml.v3" "github.com/metacubex/mihomo/component/geodata/router" - "github.com/sagernet/sing-box/option" "github.com/spf13/cobra" ) @@ -171,11 +170,12 @@ func convertSite(cmd *cobra.Command, args []string) error { if err != nil { fmt.Println(code, " output err: ", err) } - err = os.WriteFile(outDir+"/"+code+".list", []byte(strings.Join(domain, "\n")), 0755) + domainOut = []byte(strings.Join(domain, "\n")) + err = os.WriteFile(outDir+"/"+code+".list", domainOut, 0755) if err != nil { fmt.Println(code, " output err: ", err) } - err = meta.SaveMetaRuleSet(domainOut, "domain", "yaml", outDir+"/"+code+".mrs") + err = meta.SaveMetaRuleSet(domainOut, "domain", "list", outDir+"/"+code+".mrs") if err != nil { fmt.Println(code, " output err: ", err) } @@ -190,15 +190,16 @@ func convertSite(cmd *cobra.Command, args []string) error { if err != nil { fmt.Println(code, " output err: ", err) } - err = os.WriteFile(outDir+"/classical/"+code+".list", []byte(strings.Join(classical[code], "\n")), 0755) + classicalOut = []byte(strings.Join(classical[code], "\n")) + err = os.WriteFile(outDir+"/classical/"+code+".list", classicalOut, 0755) if err != nil { fmt.Println(code, " output err: ", err) } - // meta.SaveMetaRuleSet(classicalOut, "classical", "yaml", outDir+"/classical/"+code+".mrs") + // meta.SaveMetaRuleSet(classicalOut, "classical", "text", outDir+"/classical/"+code+".mrs") } case "sing-box": for code, domain := range domainFull { - domainRule := []option.DefaultHeadlessRule{ + domainRule := []sing.DefaultHeadlessRule{ { Domain: domain, DomainKeyword: domainKeyword[code], diff --git a/output/meta/meta_ruleset.go b/output/meta/meta_ruleset.go index 61b912f..0e24c61 100644 --- a/output/meta/meta_ruleset.go +++ b/output/meta/meta_ruleset.go @@ -20,10 +20,10 @@ func SaveMetaRuleSet(buf []byte, b string, f string, outputPath string) error { if err != nil { return err } - RP.ConvertToMrs(buf, behavior, format, targetFile) - err = targetFile.Close() + err = RP.ConvertToMrs(buf, behavior, format, targetFile) + closeErr := targetFile.Close() if err != nil { return err } - return nil + return closeErr } diff --git a/output/sing/sing_ruleset.go b/output/sing/sing_ruleset.go index 63f25b2..869bb6d 100644 --- a/output/sing/sing_ruleset.go +++ b/output/sing/sing_ruleset.go @@ -12,7 +12,9 @@ import ( "github.com/sagernet/sing/common/json" ) -func SaveSingRuleSet(rules []option.DefaultHeadlessRule, outputPath string) error { +type DefaultHeadlessRule = option.DefaultHeadlessRule + +func SaveSingRuleSet(rules []DefaultHeadlessRule, outputPath string) error { plainRuleSet := option.PlainRuleSetCompat{ Version: 1, Options: option.PlainRuleSet{