diff options
| author | Loyalsoldier <[email protected]> | 2024-10-31 10:51:58 +0800 |
|---|---|---|
| committer | Loyalsoldier <[email protected]> | 2024-10-31 11:21:57 +0800 |
| commit | 883184cbdc5fff0763c56aae7b08b0605dc08a9b (patch) | |
| tree | b1def962ecffe4c2d4be37e77597dd4772ae3e1f /plugin | |
| parent | 1e26c9803d42d3601c75c4db2ee3ff565b6388d8 (diff) | |
Feat: export input & output converters
Diffstat (limited to 'plugin')
| -rw-r--r-- | plugin/maxmind/asn_csv.go | 30 | ||||
| -rw-r--r-- | plugin/maxmind/country_csv.go | 30 | ||||
| -rw-r--r-- | plugin/maxmind/mmdb_in.go | 28 | ||||
| -rw-r--r-- | plugin/maxmind/mmdb_out.go | 32 | ||||
| -rw-r--r-- | plugin/mihomo/mrs_in.go | 40 | ||||
| -rw-r--r-- | plugin/mihomo/mrs_out.go | 34 | ||||
| -rw-r--r-- | plugin/plaintext/clash_in.go | 24 | ||||
| -rw-r--r-- | plugin/plaintext/clash_out.go | 24 | ||||
| -rw-r--r-- | plugin/plaintext/common_in.go | 26 | ||||
| -rw-r--r-- | plugin/plaintext/common_out.go | 34 | ||||
| -rw-r--r-- | plugin/plaintext/json_in.go | 12 | ||||
| -rw-r--r-- | plugin/plaintext/surge_in.go | 12 | ||||
| -rw-r--r-- | plugin/plaintext/surge_out.go | 12 | ||||
| -rw-r--r-- | plugin/plaintext/text_in.go | 36 | ||||
| -rw-r--r-- | plugin/plaintext/text_out.go | 22 | ||||
| -rw-r--r-- | plugin/singbox/srs_in.go | 38 | ||||
| -rw-r--r-- | plugin/singbox/srs_out.go | 34 | ||||
| -rw-r--r-- | plugin/special/cutter.go | 30 | ||||
| -rw-r--r-- | plugin/special/lookup.go | 28 | ||||
| -rw-r--r-- | plugin/special/private.go | 26 | ||||
| -rw-r--r-- | plugin/special/stdin.go | 28 | ||||
| -rw-r--r-- | plugin/special/stdout.go | 30 | ||||
| -rw-r--r-- | plugin/v2ray/dat_in.go | 34 | ||||
| -rw-r--r-- | plugin/v2ray/dat_out.go | 34 |
24 files changed, 339 insertions, 339 deletions
diff --git a/plugin/maxmind/asn_csv.go b/plugin/maxmind/asn_csv.go index 8c90d60d..a0882683 100644 --- a/plugin/maxmind/asn_csv.go +++ b/plugin/maxmind/asn_csv.go @@ -13,8 +13,8 @@ import ( ) const ( - typeASNCSV = "maxmindGeoLite2ASNCSV" - descASNCSV = "Convert MaxMind GeoLite2 ASN CSV data to other formats" + TypeASNCSV = "maxmindGeoLite2ASNCSV" + DescASNCSV = "Convert MaxMind GeoLite2 ASN CSV data to other formats" ) var ( @@ -23,11 +23,11 @@ var ( ) func init() { - lib.RegisterInputConfigCreator(typeASNCSV, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { + lib.RegisterInputConfigCreator(TypeASNCSV, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { return newGeoLite2ASNCSV(action, data) }) - lib.RegisterInputConverter(typeASNCSV, &geoLite2ASNCSV{ - Description: descASNCSV, + lib.RegisterInputConverter(TypeASNCSV, &GeoLite2ASNCSV{ + Description: DescASNCSV, }) } @@ -77,13 +77,13 @@ func newGeoLite2ASNCSV(action lib.Action, data json.RawMessage) (lib.InputConver } if len(wantList) == 0 { - return nil, fmt.Errorf("❌ [type %s | action %s] wantedList must be specified in config", typeASNCSV, action) + return nil, fmt.Errorf("❌ [type %s | action %s] wantedList must be specified in config", TypeASNCSV, action) } - return &geoLite2ASNCSV{ - Type: typeASNCSV, + return &GeoLite2ASNCSV{ + Type: TypeASNCSV, Action: action, - Description: descASNCSV, + Description: DescASNCSV, IPv4File: tmp.IPv4File, IPv6File: tmp.IPv6File, Want: wantList, @@ -91,7 +91,7 @@ func newGeoLite2ASNCSV(action lib.Action, data json.RawMessage) (lib.InputConver }, nil } -type geoLite2ASNCSV struct { +type GeoLite2ASNCSV struct { Type string Action lib.Action Description string @@ -101,19 +101,19 @@ type geoLite2ASNCSV struct { OnlyIPType lib.IPType } -func (g *geoLite2ASNCSV) GetType() string { +func (g *GeoLite2ASNCSV) GetType() string { return g.Type } -func (g *geoLite2ASNCSV) GetAction() lib.Action { +func (g *GeoLite2ASNCSV) GetAction() lib.Action { return g.Action } -func (g *geoLite2ASNCSV) GetDescription() string { +func (g *GeoLite2ASNCSV) GetDescription() string { return g.Description } -func (g *geoLite2ASNCSV) Input(container lib.Container) (lib.Container, error) { +func (g *GeoLite2ASNCSV) Input(container lib.Container) (lib.Container, error) { entries := make(map[string]*lib.Entry) if g.IPv4File != "" { @@ -158,7 +158,7 @@ func (g *geoLite2ASNCSV) Input(container lib.Container) (lib.Container, error) { return container, nil } -func (g *geoLite2ASNCSV) process(file string, entries map[string]*lib.Entry) error { +func (g *GeoLite2ASNCSV) process(file string, entries map[string]*lib.Entry) error { if entries == nil { entries = make(map[string]*lib.Entry) } diff --git a/plugin/maxmind/country_csv.go b/plugin/maxmind/country_csv.go index eb538dec..ca58964d 100644 --- a/plugin/maxmind/country_csv.go +++ b/plugin/maxmind/country_csv.go @@ -13,8 +13,8 @@ import ( ) const ( - typeCountryCSV = "maxmindGeoLite2CountryCSV" - descCountryCSV = "Convert MaxMind GeoLite2 country CSV data to other formats" + TypeCountryCSV = "maxmindGeoLite2CountryCSV" + DescCountryCSV = "Convert MaxMind GeoLite2 country CSV data to other formats" ) var ( @@ -24,11 +24,11 @@ var ( ) func init() { - lib.RegisterInputConfigCreator(typeCountryCSV, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { + lib.RegisterInputConfigCreator(TypeCountryCSV, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { return newGeoLite2CountryCSV(action, data) }) - lib.RegisterInputConverter(typeCountryCSV, &geoLite2CountryCSV{ - Description: descCountryCSV, + lib.RegisterInputConverter(TypeCountryCSV, &GeoLite2CountryCSV{ + Description: DescCountryCSV, }) } @@ -67,10 +67,10 @@ func newGeoLite2CountryCSV(action lib.Action, data json.RawMessage) (lib.InputCo } } - return &geoLite2CountryCSV{ - Type: typeCountryCSV, + return &GeoLite2CountryCSV{ + Type: TypeCountryCSV, Action: action, - Description: descCountryCSV, + Description: DescCountryCSV, CountryCodeFile: tmp.CountryCodeFile, IPv4File: tmp.IPv4File, IPv6File: tmp.IPv6File, @@ -79,7 +79,7 @@ func newGeoLite2CountryCSV(action lib.Action, data json.RawMessage) (lib.InputCo }, nil } -type geoLite2CountryCSV struct { +type GeoLite2CountryCSV struct { Type string Action lib.Action Description string @@ -90,19 +90,19 @@ type geoLite2CountryCSV struct { OnlyIPType lib.IPType } -func (g *geoLite2CountryCSV) GetType() string { +func (g *GeoLite2CountryCSV) GetType() string { return g.Type } -func (g *geoLite2CountryCSV) GetAction() lib.Action { +func (g *GeoLite2CountryCSV) GetAction() lib.Action { return g.Action } -func (g *geoLite2CountryCSV) GetDescription() string { +func (g *GeoLite2CountryCSV) GetDescription() string { return g.Description } -func (g *geoLite2CountryCSV) Input(container lib.Container) (lib.Container, error) { +func (g *GeoLite2CountryCSV) Input(container lib.Container) (lib.Container, error) { ccMap, err := g.getCountryCode() if err != nil { return nil, err @@ -152,7 +152,7 @@ func (g *geoLite2CountryCSV) Input(container lib.Container) (lib.Container, erro return container, nil } -func (g *geoLite2CountryCSV) getCountryCode() (map[string]string, error) { +func (g *GeoLite2CountryCSV) getCountryCode() (map[string]string, error) { var f io.ReadCloser var err error switch { @@ -199,7 +199,7 @@ func (g *geoLite2CountryCSV) getCountryCode() (map[string]string, error) { return ccMap, nil } -func (g *geoLite2CountryCSV) process(file string, ccMap map[string]string, entries map[string]*lib.Entry) error { +func (g *GeoLite2CountryCSV) process(file string, ccMap map[string]string, entries map[string]*lib.Entry) error { if len(ccMap) == 0 { return fmt.Errorf("❌ [type %s | action %s] invalid country code data", g.Type, g.Action) } diff --git a/plugin/maxmind/mmdb_in.go b/plugin/maxmind/mmdb_in.go index fc891c7a..80fa2523 100644 --- a/plugin/maxmind/mmdb_in.go +++ b/plugin/maxmind/mmdb_in.go @@ -12,8 +12,8 @@ import ( ) const ( - typeMaxmindMMDBIn = "maxmindMMDB" - descMaxmindMMDBIn = "Convert MaxMind mmdb database to other formats" + TypeMaxmindMMDBIn = "maxmindMMDB" + DescMaxmindMMDBIn = "Convert MaxMind mmdb database to other formats" ) var ( @@ -21,11 +21,11 @@ var ( ) func init() { - lib.RegisterInputConfigCreator(typeMaxmindMMDBIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { + lib.RegisterInputConfigCreator(TypeMaxmindMMDBIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { return newMaxmindMMDBIn(action, data) }) - lib.RegisterInputConverter(typeMaxmindMMDBIn, &maxmindMMDBIn{ - Description: descMaxmindMMDBIn, + lib.RegisterInputConverter(TypeMaxmindMMDBIn, &MaxmindMMDBIn{ + Description: DescMaxmindMMDBIn, }) } @@ -54,17 +54,17 @@ func newMaxmindMMDBIn(action lib.Action, data json.RawMessage) (lib.InputConvert } } - return &maxmindMMDBIn{ - Type: typeMaxmindMMDBIn, + return &MaxmindMMDBIn{ + Type: TypeMaxmindMMDBIn, Action: action, - Description: descMaxmindMMDBIn, + Description: DescMaxmindMMDBIn, URI: tmp.URI, Want: wantList, OnlyIPType: tmp.OnlyIPType, }, nil } -type maxmindMMDBIn struct { +type MaxmindMMDBIn struct { Type string Action lib.Action Description string @@ -73,19 +73,19 @@ type maxmindMMDBIn struct { OnlyIPType lib.IPType } -func (m *maxmindMMDBIn) GetType() string { +func (m *MaxmindMMDBIn) GetType() string { return m.Type } -func (m *maxmindMMDBIn) GetAction() lib.Action { +func (m *MaxmindMMDBIn) GetAction() lib.Action { return m.Action } -func (m *maxmindMMDBIn) GetDescription() string { +func (m *MaxmindMMDBIn) GetDescription() string { return m.Description } -func (m *maxmindMMDBIn) Input(container lib.Container) (lib.Container, error) { +func (m *MaxmindMMDBIn) Input(container lib.Container) (lib.Container, error) { var content []byte var err error switch { @@ -134,7 +134,7 @@ func (m *maxmindMMDBIn) Input(container lib.Container) (lib.Container, error) { return container, nil } -func (m *maxmindMMDBIn) generateEntries(content []byte, entries map[string]*lib.Entry) error { +func (m *MaxmindMMDBIn) generateEntries(content []byte, entries map[string]*lib.Entry) error { db, err := maxminddb.FromBytes(content) if err != nil { return err diff --git a/plugin/maxmind/mmdb_out.go b/plugin/maxmind/mmdb_out.go index 3b8ba20c..08e0c04c 100644 --- a/plugin/maxmind/mmdb_out.go +++ b/plugin/maxmind/mmdb_out.go @@ -15,8 +15,8 @@ import ( ) const ( - typeMaxmindMMDBOut = "maxmindMMDB" - descMaxmindMMDBOut = "Convert data to MaxMind mmdb database format" + TypeMaxmindMMDBOut = "maxmindMMDB" + DescMaxmindMMDBOut = "Convert data to MaxMind mmdb database format" ) var ( @@ -25,11 +25,11 @@ var ( ) func init() { - lib.RegisterOutputConfigCreator(typeMaxmindMMDBOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { + lib.RegisterOutputConfigCreator(TypeMaxmindMMDBOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { return newMMDBOut(action, data) }) - lib.RegisterOutputConverter(typeMaxmindMMDBOut, &mmdbOut{ - Description: descMaxmindMMDBOut, + lib.RegisterOutputConverter(TypeMaxmindMMDBOut, &MMDBOut{ + Description: DescMaxmindMMDBOut, }) } @@ -57,10 +57,10 @@ func newMMDBOut(action lib.Action, data json.RawMessage) (lib.OutputConverter, e tmp.OutputDir = defaultOutputDir } - return &mmdbOut{ - Type: typeMaxmindMMDBOut, + return &MMDBOut{ + Type: TypeMaxmindMMDBOut, Action: action, - Description: descMaxmindMMDBOut, + Description: DescMaxmindMMDBOut, OutputName: tmp.OutputName, OutputDir: tmp.OutputDir, Want: tmp.Want, @@ -70,7 +70,7 @@ func newMMDBOut(action lib.Action, data json.RawMessage) (lib.OutputConverter, e }, nil } -type mmdbOut struct { +type MMDBOut struct { Type string Action lib.Action Description string @@ -82,19 +82,19 @@ type mmdbOut struct { OnlyIPType lib.IPType } -func (m *mmdbOut) GetType() string { +func (m *MMDBOut) GetType() string { return m.Type } -func (m *mmdbOut) GetAction() lib.Action { +func (m *MMDBOut) GetAction() lib.Action { return m.Action } -func (m *mmdbOut) GetDescription() string { +func (m *MMDBOut) GetDescription() string { return m.Description } -func (m *mmdbOut) Output(container lib.Container) error { +func (m *MMDBOut) Output(container lib.Container) error { writer, err := mmdbwriter.New( mmdbwriter.Options{ DatabaseType: "GeoLite2-Country", @@ -129,7 +129,7 @@ func (m *mmdbOut) Output(container lib.Container) error { return nil } -func (m *mmdbOut) filterAndSortList(container lib.Container) []string { +func (m *MMDBOut) filterAndSortList(container lib.Container) []string { /* Note: The IPs and/or CIDRs of the latter list will overwrite those of the former one when duplicated data found due to MaxMind mmdb file format constraint. @@ -185,7 +185,7 @@ func (m *mmdbOut) filterAndSortList(container lib.Container) []string { return list } -func (m *mmdbOut) marshalData(writer *mmdbwriter.Tree, entry *lib.Entry) error { +func (m *MMDBOut) marshalData(writer *mmdbwriter.Tree, entry *lib.Entry) error { var entryCidr []string var err error switch m.OnlyIPType { @@ -219,7 +219,7 @@ func (m *mmdbOut) marshalData(writer *mmdbwriter.Tree, entry *lib.Entry) error { return nil } -func (m *mmdbOut) writeFile(filename string, writer *mmdbwriter.Tree) error { +func (m *MMDBOut) writeFile(filename string, writer *mmdbwriter.Tree) error { if err := os.MkdirAll(m.OutputDir, 0755); err != nil { return err } diff --git a/plugin/mihomo/mrs_in.go b/plugin/mihomo/mrs_in.go index a3ab9364..42376465 100644 --- a/plugin/mihomo/mrs_in.go +++ b/plugin/mihomo/mrs_in.go @@ -21,16 +21,16 @@ import ( var mrsMagicBytes = [4]byte{'M', 'R', 'S', 1} // MRSv1 const ( - typeMRSIn = "mihomoMRS" - descMRSIn = "Convert mihomo MRS data to other formats" + TypeMRSIn = "mihomoMRS" + DescMRSIn = "Convert mihomo MRS data to other formats" ) func init() { - lib.RegisterInputConfigCreator(typeMRSIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { + lib.RegisterInputConfigCreator(TypeMRSIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { return newMRSIn(action, data) }) - lib.RegisterInputConverter(typeMRSIn, &mrsIn{ - Description: descMRSIn, + lib.RegisterInputConverter(TypeMRSIn, &MRSIn{ + Description: DescMRSIn, }) } @@ -50,11 +50,11 @@ func newMRSIn(action lib.Action, data json.RawMessage) (lib.InputConverter, erro } if tmp.Name == "" && tmp.URI == "" && tmp.InputDir == "" { - return nil, fmt.Errorf("❌ [type %s | action %s] missing inputDir or name or uri", typeMRSIn, action) + return nil, fmt.Errorf("❌ [type %s | action %s] missing inputDir or name or uri", TypeMRSIn, action) } if (tmp.Name != "" && tmp.URI == "") || (tmp.Name == "" && tmp.URI != "") { - return nil, fmt.Errorf("❌ [type %s | action %s] name & uri must be specified together", typeMRSIn, action) + return nil, fmt.Errorf("❌ [type %s | action %s] name & uri must be specified together", TypeMRSIn, action) } // Filter want list @@ -65,10 +65,10 @@ func newMRSIn(action lib.Action, data json.RawMessage) (lib.InputConverter, erro } } - return &mrsIn{ - Type: typeMRSIn, + return &MRSIn{ + Type: TypeMRSIn, Action: action, - Description: descMRSIn, + Description: DescMRSIn, Name: tmp.Name, URI: tmp.URI, InputDir: tmp.InputDir, @@ -77,7 +77,7 @@ func newMRSIn(action lib.Action, data json.RawMessage) (lib.InputConverter, erro }, nil } -type mrsIn struct { +type MRSIn struct { Type string Action lib.Action Description string @@ -88,19 +88,19 @@ type mrsIn struct { OnlyIPType lib.IPType } -func (m *mrsIn) GetType() string { +func (m *MRSIn) GetType() string { return m.Type } -func (m *mrsIn) GetAction() lib.Action { +func (m *MRSIn) GetAction() lib.Action { return m.Action } -func (m *mrsIn) GetDescription() string { +func (m *MRSIn) GetDescription() string { return m.Description } -func (m *mrsIn) Input(container lib.Container) (lib.Container, error) { +func (m *MRSIn) Input(container lib.Container) (lib.Container, error) { entries := make(map[string]*lib.Entry) var err error @@ -152,7 +152,7 @@ func (m *mrsIn) Input(container lib.Container) (lib.Container, error) { return container, nil } -func (m *mrsIn) walkDir(dir string, entries map[string]*lib.Entry) error { +func (m *MRSIn) walkDir(dir string, entries map[string]*lib.Entry) error { err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { if err != nil { return err @@ -171,7 +171,7 @@ func (m *mrsIn) walkDir(dir string, entries map[string]*lib.Entry) error { return err } -func (m *mrsIn) walkLocalFile(path, name string, entries map[string]*lib.Entry) error { +func (m *MRSIn) walkLocalFile(path, name string, entries map[string]*lib.Entry) error { entryName := "" name = strings.TrimSpace(name) if name != "" { @@ -209,7 +209,7 @@ func (m *mrsIn) walkLocalFile(path, name string, entries map[string]*lib.Entry) return nil } -func (m *mrsIn) walkRemoteFile(url, name string, entries map[string]*lib.Entry) error { +func (m *MRSIn) walkRemoteFile(url, name string, entries map[string]*lib.Entry) error { resp, err := http.Get(url) if err != nil { return err @@ -227,7 +227,7 @@ func (m *mrsIn) walkRemoteFile(url, name string, entries map[string]*lib.Entry) return nil } -func (m *mrsIn) generateEntries(name string, reader io.Reader, entries map[string]*lib.Entry) error { +func (m *MRSIn) generateEntries(name string, reader io.Reader, entries map[string]*lib.Entry) error { name = strings.ToUpper(name) if len(m.Want) > 0 && !m.Want[name] { @@ -253,7 +253,7 @@ func (m *mrsIn) generateEntries(name string, reader io.Reader, entries map[strin return nil } -func (m *mrsIn) parseMRS(data []byte, entry *lib.Entry) error { +func (m *MRSIn) parseMRS(data []byte, entry *lib.Entry) error { reader, err := zstd.NewReader(bytes.NewReader(data)) if err != nil { return err diff --git a/plugin/mihomo/mrs_out.go b/plugin/mihomo/mrs_out.go index 28b922b3..7d63788c 100644 --- a/plugin/mihomo/mrs_out.go +++ b/plugin/mihomo/mrs_out.go @@ -17,8 +17,8 @@ import ( ) const ( - typeMRSOut = "mihomoMRS" - descMRSOut = "Convert data to mihomo MRS format" + TypeMRSOut = "mihomoMRS" + DescMRSOut = "Convert data to mihomo MRS format" ) var ( @@ -26,11 +26,11 @@ var ( ) func init() { - lib.RegisterOutputConfigCreator(typeMRSOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { + lib.RegisterOutputConfigCreator(TypeMRSOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { return newMRSOut(action, data) }) - lib.RegisterOutputConverter(typeMRSOut, &mrsOut{ - Description: descMRSOut, + lib.RegisterOutputConverter(TypeMRSOut, &MRSOut{ + Description: DescMRSOut, }) } @@ -52,10 +52,10 @@ func newMRSOut(action lib.Action, data json.RawMessage) (lib.OutputConverter, er tmp.OutputDir = defaultOutputDir } - return &mrsOut{ - Type: typeMRSOut, + return &MRSOut{ + Type: TypeMRSOut, Action: action, - Description: descMRSOut, + Description: DescMRSOut, OutputDir: tmp.OutputDir, Want: tmp.Want, Exclude: tmp.Exclude, @@ -63,7 +63,7 @@ func newMRSOut(action lib.Action, data json.RawMessage) (lib.OutputConverter, er }, nil } -type mrsOut struct { +type MRSOut struct { Type string Action lib.Action Description string @@ -73,19 +73,19 @@ type mrsOut struct { OnlyIPType lib.IPType } -func (m *mrsOut) GetType() string { +func (m *MRSOut) GetType() string { return m.Type } -func (m *mrsOut) GetAction() lib.Action { +func (m *MRSOut) GetAction() lib.Action { return m.Action } -func (m *mrsOut) GetDescription() string { +func (m *MRSOut) GetDescription() string { return m.Description } -func (m *mrsOut) Output(container lib.Container) error { +func (m *MRSOut) Output(container lib.Container) error { for _, name := range m.filterAndSortList(container) { entry, found := container.GetEntry(name) if !found { @@ -101,7 +101,7 @@ func (m *mrsOut) Output(container lib.Container) error { return nil } -func (m *mrsOut) filterAndSortList(container lib.Container) []string { +func (m *MRSOut) filterAndSortList(container lib.Container) []string { excludeMap := make(map[string]bool) for _, exclude := range m.Exclude { if exclude = strings.ToUpper(strings.TrimSpace(exclude)); exclude != "" { @@ -137,7 +137,7 @@ func (m *mrsOut) filterAndSortList(container lib.Container) []string { return list } -func (m *mrsOut) generate(entry *lib.Entry) error { +func (m *MRSOut) generate(entry *lib.Entry) error { var ipRanges []netipx.IPRange var err error switch m.OnlyIPType { @@ -164,7 +164,7 @@ func (m *mrsOut) generate(entry *lib.Entry) error { return nil } -func (m *mrsOut) writeFile(filename string, ipRanges []netipx.IPRange) error { +func (m *MRSOut) writeFile(filename string, ipRanges []netipx.IPRange) error { if err := os.MkdirAll(m.OutputDir, 0755); err != nil { return err } @@ -185,7 +185,7 @@ func (m *mrsOut) writeFile(filename string, ipRanges []netipx.IPRange) error { return nil } -func (m *mrsOut) convertToMrs(ipRanges []netipx.IPRange, w io.Writer) (err error) { +func (m *MRSOut) convertToMrs(ipRanges []netipx.IPRange, w io.Writer) (err error) { encoder, err := zstd.NewWriter(w) if err != nil { return err diff --git a/plugin/plaintext/clash_in.go b/plugin/plaintext/clash_in.go index 7cf36338..78af932f 100644 --- a/plugin/plaintext/clash_in.go +++ b/plugin/plaintext/clash_in.go @@ -12,25 +12,25 @@ which make it possible to support more formats for the project. */ const ( - typeClashRuleSetClassicalIn = "clashRuleSetClassical" - descClashClassicalIn = "Convert classical type of Clash RuleSet to other formats (just processing IP & CIDR lines)" + TypeClashRuleSetClassicalIn = "clashRuleSetClassical" + DescClashClassicalIn = "Convert classical type of Clash RuleSet to other formats (just processing IP & CIDR lines)" - typeClashRuleSetIPCIDRIn = "clashRuleSet" - descClashRuleSetIn = "Convert ipcidr type of Clash RuleSet to other formats" + TypeClashRuleSetIPCIDRIn = "clashRuleSet" + DescClashRuleSetIn = "Convert ipcidr type of Clash RuleSet to other formats" ) func init() { - lib.RegisterInputConfigCreator(typeClashRuleSetClassicalIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { - return newTextIn(typeClashRuleSetClassicalIn, action, data) + lib.RegisterInputConfigCreator(TypeClashRuleSetClassicalIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { + return newTextIn(TypeClashRuleSetClassicalIn, action, data) }) - lib.RegisterInputConverter(typeClashRuleSetClassicalIn, &textIn{ - Description: descClashClassicalIn, + lib.RegisterInputConverter(TypeClashRuleSetClassicalIn, &TextIn{ + Description: DescClashClassicalIn, }) - lib.RegisterInputConfigCreator(typeClashRuleSetIPCIDRIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { - return newTextIn(typeClashRuleSetIPCIDRIn, action, data) + lib.RegisterInputConfigCreator(TypeClashRuleSetIPCIDRIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { + return newTextIn(TypeClashRuleSetIPCIDRIn, action, data) }) - lib.RegisterInputConverter(typeClashRuleSetIPCIDRIn, &textIn{ - Description: descClashRuleSetIn, + lib.RegisterInputConverter(TypeClashRuleSetIPCIDRIn, &TextIn{ + Description: DescClashRuleSetIn, }) } diff --git a/plugin/plaintext/clash_out.go b/plugin/plaintext/clash_out.go index a7feab75..28071c84 100644 --- a/plugin/plaintext/clash_out.go +++ b/plugin/plaintext/clash_out.go @@ -12,25 +12,25 @@ which make it possible to support more formats for the project. */ const ( - typeClashRuleSetClassicalOut = "clashRuleSetClassical" - descClashClassicalOut = "Convert data to classical type of Clash RuleSet" + TypeClashRuleSetClassicalOut = "clashRuleSetClassical" + DescClashClassicalOut = "Convert data to classical type of Clash RuleSet" - typeClashRuleSetIPCIDROut = "clashRuleSet" - descClashRuleSetOut = "Convert data to ipcidr type of Clash RuleSet" + TypeClashRuleSetIPCIDROut = "clashRuleSet" + DescClashRuleSetOut = "Convert data to ipcidr type of Clash RuleSet" ) func init() { - lib.RegisterOutputConfigCreator(typeClashRuleSetClassicalOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { - return newTextOut(typeClashRuleSetClassicalOut, action, data) + lib.RegisterOutputConfigCreator(TypeClashRuleSetClassicalOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { + return newTextOut(TypeClashRuleSetClassicalOut, action, data) }) - lib.RegisterOutputConverter(typeClashRuleSetClassicalOut, &textOut{ - Description: descClashClassicalOut, + lib.RegisterOutputConverter(TypeClashRuleSetClassicalOut, &TextOut{ + Description: DescClashClassicalOut, }) - lib.RegisterOutputConfigCreator(typeClashRuleSetIPCIDROut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { - return newTextOut(typeClashRuleSetIPCIDROut, action, data) + lib.RegisterOutputConfigCreator(TypeClashRuleSetIPCIDROut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { + return newTextOut(TypeClashRuleSetIPCIDROut, action, data) }) - lib.RegisterOutputConverter(typeClashRuleSetIPCIDROut, &textOut{ - Description: descClashRuleSetOut, + lib.RegisterOutputConverter(TypeClashRuleSetIPCIDROut, &TextOut{ + Description: DescClashRuleSetOut, }) } diff --git a/plugin/plaintext/common_in.go b/plugin/plaintext/common_in.go index 06032c9d..cc7728b1 100644 --- a/plugin/plaintext/common_in.go +++ b/plugin/plaintext/common_in.go @@ -11,7 +11,7 @@ import ( "gopkg.in/yaml.v2" ) -type textIn struct { +type TextIn struct { Type string Action lib.Action Description string @@ -27,18 +27,18 @@ type textIn struct { RemoveSuffixesInLine []string } -func (t *textIn) scanFile(reader io.Reader, entry *lib.Entry) error { +func (t *TextIn) scanFile(reader io.Reader, entry *lib.Entry) error { var err error switch t.Type { - case typeTextIn: + case TypeTextIn: err = t.scanFileForTextIn(reader, entry) - case typeJSONIn: + case TypeJSONIn: err = t.scanFileForJSONIn(reader, entry) - case typeClashRuleSetClassicalIn: + case TypeClashRuleSetClassicalIn: err = t.scanFileForClashClassicalRuleSetIn(reader, entry) - case typeClashRuleSetIPCIDRIn: + case TypeClashRuleSetIPCIDRIn: err = t.scanFileForClashIPCIDRRuleSetIn(reader, entry) - case typeSurgeRuleSetIn: + case TypeSurgeRuleSetIn: err = t.scanFileForSurgeRuleSetIn(reader, entry) default: return lib.ErrNotSupportedFormat @@ -47,7 +47,7 @@ func (t *textIn) scanFile(reader io.Reader, entry *lib.Entry) error { return err } -func (t *textIn) scanFileForTextIn(reader io.Reader, entry *lib.Entry) error { +func (t *TextIn) scanFileForTextIn(reader io.Reader, entry *lib.Entry) error { scanner := bufio.NewScanner(reader) for scanner.Scan() { line := scanner.Text() @@ -83,7 +83,7 @@ func (t *textIn) scanFileForTextIn(reader io.Reader, entry *lib.Entry) error { return nil } -func (t *textIn) readClashRuleSetYAMLFile(reader io.Reader) ([]string, error) { +func (t *TextIn) readClashRuleSetYAMLFile(reader io.Reader) ([]string, error) { var payload struct { Payload []string `yaml:"payload"` } @@ -100,7 +100,7 @@ func (t *textIn) readClashRuleSetYAMLFile(reader io.Reader) ([]string, error) { return payload.Payload, nil } -func (t *textIn) scanFileForClashIPCIDRRuleSetIn(reader io.Reader, entry *lib.Entry) error { +func (t *TextIn) scanFileForClashIPCIDRRuleSetIn(reader io.Reader, entry *lib.Entry) error { payload, err := t.readClashRuleSetYAMLFile(reader) if err != nil { return err @@ -119,7 +119,7 @@ func (t *textIn) scanFileForClashIPCIDRRuleSetIn(reader io.Reader, entry *lib.En return nil } -func (t *textIn) scanFileForClashClassicalRuleSetIn(reader io.Reader, entry *lib.Entry) error { +func (t *TextIn) scanFileForClashClassicalRuleSetIn(reader io.Reader, entry *lib.Entry) error { payload, err := t.readClashRuleSetYAMLFile(reader) if err != nil { return err @@ -154,7 +154,7 @@ func (t *textIn) scanFileForClashClassicalRuleSetIn(reader io.Reader, entry *lib return nil } -func (t *textIn) scanFileForSurgeRuleSetIn(reader io.Reader, entry *lib.Entry) error { +func (t *TextIn) scanFileForSurgeRuleSetIn(reader io.Reader, entry *lib.Entry) error { scanner := bufio.NewScanner(reader) for scanner.Scan() { line := scanner.Text() @@ -193,7 +193,7 @@ func (t *textIn) scanFileForSurgeRuleSetIn(reader io.Reader, entry *lib.Entry) e return nil } -func (t *textIn) scanFileForJSONIn(reader io.Reader, entry *lib.Entry) error { +func (t *TextIn) scanFileForJSONIn(reader io.Reader, entry *lib.Entry) error { data, err := io.ReadAll(reader) if err != nil { return err diff --git a/plugin/plaintext/common_out.go b/plugin/plaintext/common_out.go index 117d48c7..4fc6375c 100644 --- a/plugin/plaintext/common_out.go +++ b/plugin/plaintext/common_out.go @@ -18,7 +18,7 @@ var ( defaultOutputDirForSurgeRuleSetOut = filepath.Join("./", "output", "surge") ) -type textOut struct { +type TextOut struct { Type string Action lib.Action Description string @@ -52,13 +52,13 @@ func newTextOut(iType string, action lib.Action, data json.RawMessage) (lib.Outp if tmp.OutputDir == "" { switch iType { - case typeTextOut: + case TypeTextOut: tmp.OutputDir = defaultOutputDirForTextOut - case typeClashRuleSetClassicalOut: + case TypeClashRuleSetClassicalOut: tmp.OutputDir = defaultOutputDirForClashRuleSetClassicalOut - case typeClashRuleSetIPCIDROut: + case TypeClashRuleSetIPCIDROut: tmp.OutputDir = defaultOutputDirForClashRuleSetIPCIDROut - case typeSurgeRuleSetOut: + case TypeSurgeRuleSetOut: tmp.OutputDir = defaultOutputDirForSurgeRuleSetOut } } @@ -67,10 +67,10 @@ func newTextOut(iType string, action lib.Action, data json.RawMessage) (lib.Outp tmp.OutputExt = ".txt" } - return &textOut{ + return &TextOut{ Type: iType, Action: action, - Description: descTextOut, + Description: DescTextOut, OutputDir: tmp.OutputDir, OutputExt: tmp.OutputExt, Want: tmp.Want, @@ -82,7 +82,7 @@ func newTextOut(iType string, action lib.Action, data json.RawMessage) (lib.Outp }, nil } -func (t *textOut) marshalBytes(entry *lib.Entry) ([]byte, error) { +func (t *TextOut) marshalBytes(entry *lib.Entry) ([]byte, error) { var err error var entryCidr []string @@ -100,13 +100,13 @@ func (t *textOut) marshalBytes(entry *lib.Entry) ([]byte, error) { var buf bytes.Buffer switch t.Type { - case typeTextOut: + case TypeTextOut: err = t.marshalBytesForTextOut(&buf, entryCidr) - case typeClashRuleSetClassicalOut: + case TypeClashRuleSetClassicalOut: err = t.marshalBytesForClashRuleSetClassicalOut(&buf, entryCidr) - case typeClashRuleSetIPCIDROut: + case TypeClashRuleSetIPCIDROut: err = t.marshalBytesForClashRuleSetIPCIDROut(&buf, entryCidr) - case typeSurgeRuleSetOut: + case TypeSurgeRuleSetOut: err = t.marshalBytesForSurgeRuleSetOut(&buf, entryCidr) default: return nil, lib.ErrNotSupportedFormat @@ -118,7 +118,7 @@ func (t *textOut) marshalBytes(entry *lib.Entry) ([]byte, error) { return buf.Bytes(), nil } -func (t *textOut) marshalBytesForTextOut(buf *bytes.Buffer, entryCidr []string) error { +func (t *TextOut) marshalBytesForTextOut(buf *bytes.Buffer, entryCidr []string) error { for _, cidr := range entryCidr { if t.AddPrefixInLine != "" { buf.WriteString(t.AddPrefixInLine) @@ -132,7 +132,7 @@ func (t *textOut) marshalBytesForTextOut(buf *bytes.Buffer, entryCidr []string) return nil } -func (t *textOut) marshalBytesForClashRuleSetClassicalOut(buf *bytes.Buffer, entryCidr []string) error { +func (t *TextOut) marshalBytesForClashRuleSetClassicalOut(buf *bytes.Buffer, entryCidr []string) error { buf.WriteString("payload:\n") for _, cidr := range entryCidr { ip, _, err := net.ParseCIDR(cidr) @@ -151,7 +151,7 @@ func (t *textOut) marshalBytesForClashRuleSetClassicalOut(buf *bytes.Buffer, ent return nil } -func (t *textOut) marshalBytesForClashRuleSetIPCIDROut(buf *bytes.Buffer, entryCidr []string) error { +func (t *TextOut) marshalBytesForClashRuleSetIPCIDROut(buf *bytes.Buffer, entryCidr []string) error { buf.WriteString("payload:\n") for _, cidr := range entryCidr { buf.WriteString(" - '") @@ -162,7 +162,7 @@ func (t *textOut) marshalBytesForClashRuleSetIPCIDROut(buf *bytes.Buffer, entryC return nil } -func (t *textOut) marshalBytesForSurgeRuleSetOut(buf *bytes.Buffer, entryCidr []string) error { +func (t *TextOut) marshalBytesForSurgeRuleSetOut(buf *bytes.Buffer, entryCidr []string) error { for _, cidr := range entryCidr { ip, _, err := net.ParseCIDR(cidr) if err != nil { @@ -183,7 +183,7 @@ func (t *textOut) marshalBytesForSurgeRuleSetOut(buf *bytes.Buffer, entryCidr [] return nil } -func (t *textOut) writeFile(filename string, data []byte) error { +func (t *TextOut) writeFile(filename string, data []byte) error { if err := os.MkdirAll(t.OutputDir, 0755); err != nil { return err } diff --git a/plugin/plaintext/json_in.go b/plugin/plaintext/json_in.go index 784eba09..14af7c87 100644 --- a/plugin/plaintext/json_in.go +++ b/plugin/plaintext/json_in.go @@ -7,16 +7,16 @@ import ( ) const ( - typeJSONIn = "json" - descJSONIn = "Convert JSON data to other formats" + TypeJSONIn = "json" + DescJSONIn = "Convert JSON data to other formats" ) func init() { - lib.RegisterInputConfigCreator(typeJSONIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { - return newTextIn(typeJSONIn, action, data) + lib.RegisterInputConfigCreator(TypeJSONIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { + return newTextIn(TypeJSONIn, action, data) }) - lib.RegisterInputConverter(typeJSONIn, &textIn{ - Description: descJSONIn, + lib.RegisterInputConverter(TypeJSONIn, &TextIn{ + Description: DescJSONIn, }) } diff --git a/plugin/plaintext/surge_in.go b/plugin/plaintext/surge_in.go index d409a782..ebe7f37a 100644 --- a/plugin/plaintext/surge_in.go +++ b/plugin/plaintext/surge_in.go @@ -12,15 +12,15 @@ which make it possible to support more formats for the project. */ const ( - typeSurgeRuleSetIn = "surgeRuleSet" - descSurgeRuleSetIn = "Convert Surge RuleSet to other formats (just processing IP & CIDR lines)" + TypeSurgeRuleSetIn = "surgeRuleSet" + DescSurgeRuleSetIn = "Convert Surge RuleSet to other formats (just processing IP & CIDR lines)" ) func init() { - lib.RegisterInputConfigCreator(typeSurgeRuleSetIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { - return newTextIn(typeSurgeRuleSetIn, action, data) + lib.RegisterInputConfigCreator(TypeSurgeRuleSetIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { + return newTextIn(TypeSurgeRuleSetIn, action, data) }) - lib.RegisterInputConverter(typeSurgeRuleSetIn, &textIn{ - Description: descSurgeRuleSetIn, + lib.RegisterInputConverter(TypeSurgeRuleSetIn, &TextIn{ + Description: DescSurgeRuleSetIn, }) } diff --git a/plugin/plaintext/surge_out.go b/plugin/plaintext/surge_out.go index c3868423..6af83271 100644 --- a/plugin/plaintext/surge_out.go +++ b/plugin/plaintext/surge_out.go @@ -12,15 +12,15 @@ which make it possible to support more formats for the project. */ const ( - typeSurgeRuleSetOut = "surgeRuleSet" - descSurgeRuleSetOut = "Convert data to Surge RuleSet" + TypeSurgeRuleSetOut = "surgeRuleSet" + DescSurgeRuleSetOut = "Convert data to Surge RuleSet" ) func init() { - lib.RegisterOutputConfigCreator(typeSurgeRuleSetOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { - return newTextOut(typeSurgeRuleSetOut, action, data) + lib.RegisterOutputConfigCreator(TypeSurgeRuleSetOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { + return newTextOut(TypeSurgeRuleSetOut, action, data) }) - lib.RegisterOutputConverter(typeSurgeRuleSetOut, &textOut{ - Description: descSurgeRuleSetOut, + lib.RegisterOutputConverter(TypeSurgeRuleSetOut, &TextOut{ + Description: DescSurgeRuleSetOut, }) } diff --git a/plugin/plaintext/text_in.go b/plugin/plaintext/text_in.go index 68d60eaa..f129c3cb 100644 --- a/plugin/plaintext/text_in.go +++ b/plugin/plaintext/text_in.go @@ -13,16 +13,16 @@ import ( ) const ( - typeTextIn = "text" - descTextIn = "Convert plaintext IP & CIDR to other formats" + TypeTextIn = "text" + DescTextIn = "Convert plaintext IP & CIDR to other formats" ) func init() { - lib.RegisterInputConfigCreator(typeTextIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { - return newTextIn(typeTextIn, action, data) + lib.RegisterInputConfigCreator(TypeTextIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { + return newTextIn(TypeTextIn, action, data) }) - lib.RegisterInputConverter(typeTextIn, &textIn{ - Description: descTextIn, + lib.RegisterInputConverter(TypeTextIn, &TextIn{ + Description: DescTextIn, }) } @@ -50,11 +50,11 @@ func newTextIn(iType string, action lib.Action, data json.RawMessage) (lib.Input } } - if iType != typeTextIn && len(tmp.IPOrCIDR) > 0 { + if iType != TypeTextIn && len(tmp.IPOrCIDR) > 0 { return nil, fmt.Errorf("❌ [type %s | action %s] ipOrCIDR is invalid for this input format", iType, action) } - if iType == typeJSONIn && len(tmp.JSONPath) == 0 { + if iType == TypeJSONIn && len(tmp.JSONPath) == 0 { return nil, fmt.Errorf("❌ [type %s | action %s] missing jsonPath", iType, action) } @@ -77,10 +77,10 @@ func newTextIn(iType string, action lib.Action, data json.RawMessage) (lib.Input } } - return &textIn{ + return &TextIn{ Type: iType, Action: action, - Description: descTextIn, + Description: DescTextIn, Name: tmp.Name, URI: tmp.URI, IPOrCIDR: tmp.IPOrCIDR, @@ -94,19 +94,19 @@ func newTextIn(iType string, action lib.Action, data json.RawMessage) (lib.Input }, nil } -func (t *textIn) GetType() string { +func (t *TextIn) GetType() string { return t.Type } -func (t *textIn) GetAction() lib.Action { +func (t *TextIn) GetAction() lib.Action { return t.Action } -func (t *textIn) GetDescription() string { +func (t *TextIn) GetDescription() string { return t.Description } -func (t *textIn) Input(container lib.Container) (lib.Container, error) { +func (t *TextIn) Input(container lib.Container) (lib.Container, error) { entries := make(map[string]*lib.Entry) var err error @@ -168,7 +168,7 @@ func (t *textIn) Input(container lib.Container) (lib.Container, error) { return container, nil } -func (t *textIn) walkDir(dir string, entries map[string]*lib.Entry) error { +func (t *TextIn) walkDir(dir string, entries map[string]*lib.Entry) error { err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { if err != nil { return err @@ -187,7 +187,7 @@ func (t *textIn) walkDir(dir string, entries map[string]*lib.Entry) error { return err } -func (t *textIn) walkLocalFile(path, name string, entries map[string]*lib.Entry) error { +func (t *TextIn) walkLocalFile(path, name string, entries map[string]*lib.Entry) error { entryName := "" name = strings.TrimSpace(name) if name != "" { @@ -231,7 +231,7 @@ func (t *textIn) walkLocalFile(path, name string, entries map[string]*lib.Entry) return nil } -func (t *textIn) walkRemoteFile(url, name string, entries map[string]*lib.Entry) error { +func (t *TextIn) walkRemoteFile(url, name string, entries map[string]*lib.Entry) error { resp, err := http.Get(url) if err != nil { return err @@ -258,7 +258,7 @@ func (t *textIn) walkRemoteFile(url, name string, entries map[string]*lib.Entry) return nil } -func (t *textIn) appendIPOrCIDR(ipOrCIDR []string, name string, entries map[string]*lib.Entry) error { +func (t *TextIn) appendIPOrCIDR(ipOrCIDR []string, name string, entries map[string]*lib.Entry) error { name = strings.ToUpper(name) entry, found := entries[name] diff --git a/plugin/plaintext/text_out.go b/plugin/plaintext/text_out.go index cc51da95..41c6065b 100644 --- a/plugin/plaintext/text_out.go +++ b/plugin/plaintext/text_out.go @@ -10,32 +10,32 @@ import ( ) const ( - typeTextOut = "text" - descTextOut = "Convert data to plaintext CIDR format" + TypeTextOut = "text" + DescTextOut = "Convert data to plaintext CIDR format" ) func init() { - lib.RegisterOutputConfigCreator(typeTextOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { - return newTextOut(typeTextOut, action, data) + lib.RegisterOutputConfigCreator(TypeTextOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { + return newTextOut(TypeTextOut, action, data) }) - lib.RegisterOutputConverter(typeTextOut, &textOut{ - Description: descTextOut, + lib.RegisterOutputConverter(TypeTextOut, &TextOut{ + Description: DescTextOut, }) } -func (t *textOut) GetType() string { +func (t *TextOut) GetType() string { return t.Type } -func (t *textOut) GetAction() lib.Action { +func (t *TextOut) GetAction() lib.Action { return t.Action } -func (t *textOut) GetDescription() string { +func (t *TextOut) GetDescription() string { return t.Description } -func (t *textOut) Output(container lib.Container) error { +func (t *TextOut) Output(container lib.Container) error { for _, name := range t.filterAndSortList(container) { entry, found := container.GetEntry(name) if !found { @@ -57,7 +57,7 @@ func (t *textOut) Output(container lib.Container) error { return nil } -func (t *textOut) filterAndSortList(container lib.Container) []string { +func (t *TextOut) filterAndSortList(container lib.Container) []string { excludeMap := make(map[string]bool) for _, exclude := range t.Exclude { if exclude = strings.ToUpper(strings.TrimSpace(exclude)); exclude != "" { diff --git a/plugin/singbox/srs_in.go b/plugin/singbox/srs_in.go index f38c53cd..13dd51af 100644 --- a/plugin/singbox/srs_in.go +++ b/plugin/singbox/srs_in.go @@ -15,16 +15,16 @@ import ( ) const ( - typeSRSIn = "singboxSRS" - descSRSIn = "Convert sing-box SRS data to other formats" + TypeSRSIn = "singboxSRS" + DescSRSIn = "Convert sing-box SRS data to other formats" ) func init() { - lib.RegisterInputConfigCreator(typeSRSIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { + lib.RegisterInputConfigCreator(TypeSRSIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { return newSRSIn(action, data) }) - lib.RegisterInputConverter(typeSRSIn, &srsIn{ - Description: descSRSIn, + lib.RegisterInputConverter(TypeSRSIn, &SRSIn{ + Description: DescSRSIn, }) } @@ -44,11 +44,11 @@ func newSRSIn(action lib.Action, data json.RawMessage) (lib.InputConverter, erro } if tmp.Name == "" && tmp.URI == "" && tmp.InputDir == "" { - return nil, fmt.Errorf("❌ [type %s | action %s] missing inputdir or name or uri", typeSRSIn, action) + return nil, fmt.Errorf("❌ [type %s | action %s] missing inputdir or name or uri", TypeSRSIn, action) } if (tmp.Name != "" && tmp.URI == "") || (tmp.Name == "" && tmp.URI != "") { - return nil, fmt.Errorf("❌ [type %s | action %s] name & uri must be specified together", typeSRSIn, action) + return nil, fmt.Errorf("❌ [type %s | action %s] name & uri must be specified together", TypeSRSIn, action) } // Filter want list @@ -59,10 +59,10 @@ func newSRSIn(action lib.Action, data json.RawMessage) (lib.InputConverter, erro } } - return &srsIn{ - Type: typeSRSIn, + return &SRSIn{ + Type: TypeSRSIn, Action: action, - Description: descSRSIn, + Description: DescSRSIn, Name: tmp.Name, URI: tmp.URI, InputDir: tmp.InputDir, @@ -71,7 +71,7 @@ func newSRSIn(action lib.Action, data json.RawMessage) (lib.InputConverter, erro }, nil } -type srsIn struct { +type SRSIn struct { Type string Action lib.Action Description string @@ -82,19 +82,19 @@ type srsIn struct { OnlyIPType lib.IPType } -func (s *srsIn) GetType() string { +func (s *SRSIn) GetType() string { return s.Type } -func (s *srsIn) GetAction() lib.Action { +func (s *SRSIn) GetAction() lib.Action { return s.Action } -func (s *srsIn) GetDescription() string { +func (s *SRSIn) GetDescription() string { return s.Description } -func (s *srsIn) Input(container lib.Container) (lib.Container, error) { +func (s *SRSIn) Input(container lib.Container) (lib.Container, error) { entries := make(map[string]*lib.Entry) var err error @@ -146,7 +146,7 @@ func (s *srsIn) Input(container lib.Container) (lib.Container, error) { return container, nil } -func (s *srsIn) walkDir(dir string, entries map[string]*lib.Entry) error { +func (s *SRSIn) walkDir(dir string, entries map[string]*lib.Entry) error { err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { if err != nil { return err @@ -165,7 +165,7 @@ func (s *srsIn) walkDir(dir string, entries map[string]*lib.Entry) error { return err } -func (s *srsIn) walkLocalFile(path, name string, entries map[string]*lib.Entry) error { +func (s *SRSIn) walkLocalFile(path, name string, entries map[string]*lib.Entry) error { entryName := "" name = strings.TrimSpace(name) if name != "" { @@ -203,7 +203,7 @@ func (s *srsIn) walkLocalFile(path, name string, entries map[string]*lib.Entry) return nil } -func (s *srsIn) walkRemoteFile(url, name string, entries map[string]*lib.Entry) error { +func (s *SRSIn) walkRemoteFile(url, name string, entries map[string]*lib.Entry) error { resp, err := http.Get(url) if err != nil { return err @@ -221,7 +221,7 @@ func (s *srsIn) walkRemoteFile(url, name string, entries map[string]*lib.Entry) return nil } -func (s *srsIn) generateEntries(name string, reader io.Reader, entries map[string]*lib.Entry) error { +func (s *SRSIn) generateEntries(name string, reader io.Reader, entries map[string]*lib.Entry) error { name = strings.ToUpper(name) if len(s.Want) > 0 && !s.Want[name] { diff --git a/plugin/singbox/srs_out.go b/plugin/singbox/srs_out.go index a17e1fa7..e613b993 100644 --- a/plugin/singbox/srs_out.go +++ b/plugin/singbox/srs_out.go @@ -16,8 +16,8 @@ import ( ) const ( - typeSRSOut = "singboxSRS" - descSRSOut = "Convert data to sing-box SRS format" + TypeSRSOut = "singboxSRS" + DescSRSOut = "Convert data to sing-box SRS format" ) var ( @@ -25,11 +25,11 @@ var ( ) func init() { - lib.RegisterOutputConfigCreator(typeSRSOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { + lib.RegisterOutputConfigCreator(TypeSRSOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { return newSRSOut(action, data) }) - lib.RegisterOutputConverter(typeSRSOut, &srsOut{ - Description: descSRSOut, + lib.RegisterOutputConverter(TypeSRSOut, &SRSOut{ + Description: DescSRSOut, }) } @@ -51,10 +51,10 @@ func newSRSOut(action lib.Action, data json.RawMessage) (lib.OutputConverter, er tmp.OutputDir = defaultOutputDir } - return &srsOut{ - Type: typeSRSOut, + return &SRSOut{ + Type: TypeSRSOut, Action: action, - Description: descSRSOut, + Description: DescSRSOut, OutputDir: tmp.OutputDir, Want: tmp.Want, Exclude: tmp.Exclude, @@ -62,7 +62,7 @@ func newSRSOut(action lib.Action, data json.RawMessage) (lib.OutputConverter, er }, nil } -type srsOut struct { +type SRSOut struct { Type string Action lib.Action Description string @@ -72,19 +72,19 @@ type srsOut struct { OnlyIPType lib.IPType } -func (s *srsOut) GetType() string { +func (s *SRSOut) GetType() string { return s.Type } -func (s *srsOut) GetAction() lib.Action { +func (s *SRSOut) GetAction() lib.Action { return s.Action } -func (s *srsOut) GetDescription() string { +func (s *SRSOut) GetDescription() string { return s.Description } -func (s *srsOut) Output(container lib.Container) error { +func (s *SRSOut) Output(container lib.Container) error { for _, name := range s.filterAndSortList(container) { entry, found := container.GetEntry(name) if !found { @@ -100,7 +100,7 @@ func (s *srsOut) Output(container lib.Container) error { return nil } -func (s *srsOut) filterAndSortList(container lib.Container) []string { +func (s *SRSOut) filterAndSortList(container lib.Container) []string { excludeMap := make(map[string]bool) for _, exclude := range s.Exclude { if exclude = strings.ToUpper(strings.TrimSpace(exclude)); exclude != "" { @@ -136,7 +136,7 @@ func (s *srsOut) filterAndSortList(container lib.Container) []string { return list } -func (s *srsOut) generate(entry *lib.Entry) error { +func (s *SRSOut) generate(entry *lib.Entry) error { ruleset, err := s.marshalRuleSet(entry) if err != nil { return err @@ -150,7 +150,7 @@ func (s *srsOut) generate(entry *lib.Entry) error { return nil } -func (s *srsOut) marshalRuleSet(entry *lib.Entry) (*option.PlainRuleSet, error) { +func (s *SRSOut) marshalRuleSet(entry *lib.Entry) (*option.PlainRuleSet, error) { var entryCidr []string var err error switch s.OnlyIPType { @@ -183,7 +183,7 @@ func (s *srsOut) marshalRuleSet(entry *lib.Entry) (*option.PlainRuleSet, error) return nil, fmt.Errorf("❌ [type %s | action %s] entry %s has no CIDR", s.Type, s.Action, entry.GetName()) } -func (s *srsOut) writeFile(filename string, ruleset *option.PlainRuleSet) error { +func (s *SRSOut) writeFile(filename string, ruleset *option.PlainRuleSet) error { if err := os.MkdirAll(s.OutputDir, 0755); err != nil { return err } diff --git a/plugin/special/cutter.go b/plugin/special/cutter.go index 2b33ee27..a96431e7 100644 --- a/plugin/special/cutter.go +++ b/plugin/special/cutter.go @@ -9,16 +9,16 @@ import ( ) const ( - typeCutter = "cutter" - descCutter = "Remove data from previous steps" + TypeCutter = "cutter" + DescCutter = "Remove data from previous steps" ) func init() { - lib.RegisterInputConfigCreator(typeCutter, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { + lib.RegisterInputConfigCreator(TypeCutter, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { return newCutter(action, data) }) - lib.RegisterInputConverter(typeCutter, &cutter{ - Description: descCutter, + lib.RegisterInputConverter(TypeCutter, &Cutter{ + Description: DescCutter, }) } @@ -35,7 +35,7 @@ func newCutter(action lib.Action, data json.RawMessage) (lib.InputConverter, err } if action != lib.ActionRemove { - return nil, fmt.Errorf("❌ [type %s] only supports `remove` action", typeCutter) + return nil, fmt.Errorf("❌ [type %s] only supports `remove` action", TypeCutter) } // Filter want list @@ -47,19 +47,19 @@ func newCutter(action lib.Action, data json.RawMessage) (lib.InputConverter, err } if len(wantList) == 0 { - return nil, fmt.Errorf("❌ [type %s] wantedList must be specified", typeCutter) + return nil, fmt.Errorf("❌ [type %s] wantedList must be specified", TypeCutter) } - return &cutter{ - Type: typeCutter, + return &Cutter{ + Type: TypeCutter, Action: action, - Description: descCutter, + Description: DescCutter, Want: wantList, OnlyIPType: tmp.OnlyIPType, }, nil } -type cutter struct { +type Cutter struct { Type string Action lib.Action Description string @@ -67,19 +67,19 @@ type cutter struct { OnlyIPType lib.IPType } -func (c *cutter) GetType() string { +func (c *Cutter) GetType() string { return c.Type } -func (c *cutter) GetAction() lib.Action { +func (c *Cutter) GetAction() lib.Action { return c.Action } -func (c *cutter) GetDescription() string { +func (c *Cutter) GetDescription() string { return c.Description } -func (c *cutter) Input(container lib.Container) (lib.Container, error) { +func (c *Cutter) Input(container lib.Container) (lib.Container, error) { var ignoreIPType lib.IgnoreIPOption switch c.OnlyIPType { case lib.IPv4: diff --git a/plugin/special/lookup.go b/plugin/special/lookup.go index 6b9e6af0..96735146 100644 --- a/plugin/special/lookup.go +++ b/plugin/special/lookup.go @@ -12,16 +12,16 @@ import ( ) const ( - typeLookup = "lookup" - descLookup = "Lookup specified IP or CIDR from various formats of data" + TypeLookup = "lookup" + DescLookup = "Lookup specified IP or CIDR from various formats of data" ) func init() { - lib.RegisterOutputConfigCreator(typeLookup, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { + lib.RegisterOutputConfigCreator(TypeLookup, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { return newLookup(action, data) }) - lib.RegisterOutputConverter(typeLookup, &lookup{ - Description: descLookup, + lib.RegisterOutputConverter(TypeLookup, &Lookup{ + Description: DescLookup, }) } @@ -39,19 +39,19 @@ func newLookup(action lib.Action, data json.RawMessage) (lib.OutputConverter, er tmp.Search = strings.TrimSpace(tmp.Search) if tmp.Search == "" { - return nil, fmt.Errorf("❌ [type %s | action %s] please specify an IP or a CIDR as search target", typeLookup, action) + return nil, fmt.Errorf("❌ [type %s | action %s] please specify an IP or a CIDR as search target", TypeLookup, action) } - return &lookup{ - Type: typeLookup, + return &Lookup{ + Type: TypeLookup, Action: action, - Description: descLookup, + Description: DescLookup, Search: tmp.Search, SearchList: tmp.SearchList, }, nil } -type lookup struct { +type Lookup struct { Type string Action lib.Action Description string @@ -59,19 +59,19 @@ type lookup struct { SearchList []string } -func (l *lookup) GetType() string { +func (l *Lookup) GetType() string { return l.Type } -func (l *lookup) GetAction() lib.Action { +func (l *Lookup) GetAction() lib.Action { return l.Action } -func (l *lookup) GetDescription() string { +func (l *Lookup) GetDescription() string { return l.Description } -func (l *lookup) Output(container lib.Container) error { +func (l *Lookup) Output(container lib.Container) error { switch strings.Contains(l.Search, "/") { case true: // CIDR if _, err := netip.ParsePrefix(l.Search); err != nil { diff --git a/plugin/special/private.go b/plugin/special/private.go index dc781c31..5c137687 100644 --- a/plugin/special/private.go +++ b/plugin/special/private.go @@ -8,8 +8,8 @@ import ( const ( entryNamePrivate = "private" - typePrivate = "private" - descPrivate = "Convert LAN and private network CIDR to other formats" + TypePrivate = "private" + DescPrivate = "Convert LAN and private network CIDR to other formats" ) var privateCIDRs = []string{ @@ -37,11 +37,11 @@ var privateCIDRs = []string{ } func init() { - lib.RegisterInputConfigCreator(typePrivate, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { + lib.RegisterInputConfigCreator(TypePrivate, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { return newPrivate(action, data) }) - lib.RegisterInputConverter(typePrivate, &private{ - Description: descPrivate, + lib.RegisterInputConverter(TypePrivate, &Private{ + Description: DescPrivate, }) } @@ -56,34 +56,34 @@ func newPrivate(action lib.Action, data json.RawMessage) (lib.InputConverter, er } } - return &private{ - Type: typePrivate, + return &Private{ + Type: TypePrivate, Action: action, - Description: descPrivate, + Description: DescPrivate, OnlyIPType: tmp.OnlyIPType, }, nil } -type private struct { +type Private struct { Type string Action lib.Action Description string OnlyIPType lib.IPType } -func (p *private) GetType() string { +func (p *Private) GetType() string { return p.Type } -func (p *private) GetAction() lib.Action { +func (p *Private) GetAction() lib.Action { return p.Action } -func (p *private) GetDescription() string { +func (p *Private) GetDescription() string { return p.Description } -func (p *private) Input(container lib.Container) (lib.Container, error) { +func (p *Private) Input(container lib.Container) (lib.Container, error) { entry, found := container.GetEntry(entryNamePrivate) if !found { entry = lib.NewEntry(entryNamePrivate) diff --git a/plugin/special/stdin.go b/plugin/special/stdin.go index 1621c351..779a4cbd 100644 --- a/plugin/special/stdin.go +++ b/plugin/special/stdin.go @@ -11,16 +11,16 @@ import ( ) const ( - typeStdin = "stdin" - descStdin = "Accept plaintext IP & CIDR from standard input, separated by newline" + TypeStdin = "stdin" + DescStdin = "Accept plaintext IP & CIDR from standard input, separated by newline" ) func init() { - lib.RegisterInputConfigCreator(typeStdin, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { + lib.RegisterInputConfigCreator(TypeStdin, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { return newStdin(action, data) }) - lib.RegisterInputConverter(typeStdin, &stdin{ - Description: descStdin, + lib.RegisterInputConverter(TypeStdin, &Stdin{ + Description: DescStdin, }) } @@ -37,19 +37,19 @@ func newStdin(action lib.Action, data json.RawMessage) (lib.InputConverter, erro } if tmp.Name == "" { - return nil, fmt.Errorf("❌ [type %s | action %s] missing name", typeStdin, action) + return nil, fmt.Errorf("❌ [type %s | action %s] missing name", TypeStdin, action) } - return &stdin{ - Type: typeStdin, + return &Stdin{ + Type: TypeStdin, Action: action, - Description: descStdin, + Description: DescStdin, Name: tmp.Name, OnlyIPType: tmp.OnlyIPType, }, nil } -type stdin struct { +type Stdin struct { Type string Action lib.Action Description string @@ -57,19 +57,19 @@ type stdin struct { OnlyIPType lib.IPType } -func (s *stdin) GetType() string { +func (s *Stdin) GetType() string { return s.Type } -func (s *stdin) GetAction() lib.Action { +func (s *Stdin) GetAction() lib.Action { return s.Action } -func (s *stdin) GetDescription() string { +func (s *Stdin) GetDescription() string { return s.Description } -func (s *stdin) Input(container lib.Container) (lib.Container, error) { +func (s *Stdin) Input(container lib.Container) (lib.Container, error) { entry := lib.NewEntry(s.Name) scanner := bufio.NewScanner(os.Stdin) diff --git a/plugin/special/stdout.go b/plugin/special/stdout.go index 8c57cb58..ed8467ed 100644 --- a/plugin/special/stdout.go +++ b/plugin/special/stdout.go @@ -12,16 +12,16 @@ import ( ) const ( - typeStdout = "stdout" - descStdout = "Convert data to plaintext CIDR format and output to standard output" + TypeStdout = "stdout" + DescStdout = "Convert data to plaintext CIDR format and output to standard output" ) func init() { - lib.RegisterOutputConfigCreator(typeStdout, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { + lib.RegisterOutputConfigCreator(TypeStdout, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { return newStdout(action, data) }) - lib.RegisterOutputConverter(typeStdout, &stdout{ - Description: descStdout, + lib.RegisterOutputConverter(TypeStdout, &Stdout{ + Description: DescStdout, }) } @@ -38,17 +38,17 @@ func newStdout(action lib.Action, data json.RawMessage) (lib.OutputConverter, er } } - return &stdout{ - Type: typeStdout, + return &Stdout{ + Type: TypeStdout, Action: action, - Description: descStdout, + Description: DescStdout, Want: tmp.Want, Exclude: tmp.Exclude, OnlyIPType: tmp.OnlyIPType, }, nil } -type stdout struct { +type Stdout struct { Type string Action lib.Action Description string @@ -57,19 +57,19 @@ type stdout struct { OnlyIPType lib.IPType } -func (s *stdout) GetType() string { +func (s *Stdout) GetType() string { return s.Type } -func (s *stdout) GetAction() lib.Action { +func (s *Stdout) GetAction() lib.Action { return s.Action } -func (s *stdout) GetDescription() string { +func (s *Stdout) GetDescription() string { return s.Description } -func (s *stdout) Output(container lib.Container) error { +func (s *Stdout) Output(container lib.Container) error { for _, name := range s.filterAndSortList(container) { entry, found := container.GetEntry(name) if !found { @@ -89,7 +89,7 @@ func (s *stdout) Output(container lib.Container) error { return nil } -func (s *stdout) filterAndSortList(container lib.Container) []string { +func (s *Stdout) filterAndSortList(container lib.Container) []string { excludeMap := make(map[string]bool) for _, exclude := range s.Exclude { if exclude = strings.ToUpper(strings.TrimSpace(exclude)); exclude != "" { @@ -125,7 +125,7 @@ func (s *stdout) filterAndSortList(container lib.Container) []string { return list } -func (s *stdout) generateCIDRList(entry *lib.Entry) ([]string, error) { +func (s *Stdout) generateCIDRList(entry *lib.Entry) ([]string, error) { var entryList []string var err error switch s.OnlyIPType { diff --git a/plugin/v2ray/dat_in.go b/plugin/v2ray/dat_in.go index 37d8bb5a..af306600 100644 --- a/plugin/v2ray/dat_in.go +++ b/plugin/v2ray/dat_in.go @@ -14,16 +14,16 @@ import ( ) const ( - typeGeoIPdatIn = "v2rayGeoIPDat" - descGeoIPdatIn = "Convert V2Ray GeoIP dat to other formats" + TypeGeoIPdatIn = "v2rayGeoIPDat" + DescGeoIPdatIn = "Convert V2Ray GeoIP dat to other formats" ) func init() { - lib.RegisterInputConfigCreator(typeGeoIPdatIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { + lib.RegisterInputConfigCreator(TypeGeoIPdatIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { return newGeoIPDatIn(action, data) }) - lib.RegisterInputConverter(typeGeoIPdatIn, &geoIPDatIn{ - Description: descGeoIPdatIn, + lib.RegisterInputConverter(TypeGeoIPdatIn, &GeoIPDatIn{ + Description: DescGeoIPdatIn, }) } @@ -41,7 +41,7 @@ func newGeoIPDatIn(action lib.Action, data json.RawMessage) (lib.InputConverter, } if tmp.URI == "" { - return nil, fmt.Errorf("❌ [type %s | action %s] uri must be specified in config", typeGeoIPdatIn, action) + return nil, fmt.Errorf("❌ [type %s | action %s] uri must be specified in config", TypeGeoIPdatIn, action) } // Filter want list @@ -52,17 +52,17 @@ func newGeoIPDatIn(action lib.Action, data json.RawMessage) (lib.InputConverter, } } - return &geoIPDatIn{ - Type: typeGeoIPdatIn, + return &GeoIPDatIn{ + Type: TypeGeoIPdatIn, Action: action, - Description: descGeoIPdatIn, + Description: DescGeoIPdatIn, URI: tmp.URI, Want: wantList, OnlyIPType: tmp.OnlyIPType, }, nil } -type geoIPDatIn struct { +type GeoIPDatIn struct { Type string Action lib.Action Description string @@ -71,19 +71,19 @@ type geoIPDatIn struct { OnlyIPType lib.IPType } -func (g *geoIPDatIn) GetType() string { +func (g *GeoIPDatIn) GetType() string { return g.Type } -func (g *geoIPDatIn) GetAction() lib.Action { +func (g *GeoIPDatIn) GetAction() lib.Action { return g.Action } -func (g *geoIPDatIn) GetDescription() string { +func (g *GeoIPDatIn) GetDescription() string { return g.Description } -func (g *geoIPDatIn) Input(container lib.Container) (lib.Container, error) { +func (g *GeoIPDatIn) Input(container lib.Container) (lib.Container, error) { entries := make(map[string]*lib.Entry) var err error @@ -128,7 +128,7 @@ func (g *geoIPDatIn) Input(container lib.Container) (lib.Container, error) { return container, nil } -func (g *geoIPDatIn) walkLocalFile(path string, entries map[string]*lib.Entry) error { +func (g *GeoIPDatIn) walkLocalFile(path string, entries map[string]*lib.Entry) error { file, err := os.Open(path) if err != nil { return err @@ -142,7 +142,7 @@ func (g *geoIPDatIn) walkLocalFile(path string, entries map[string]*lib.Entry) e return nil } -func (g *geoIPDatIn) walkRemoteFile(url string, entries map[string]*lib.Entry) error { +func (g *GeoIPDatIn) walkRemoteFile(url string, entries map[string]*lib.Entry) error { resp, err := http.Get(url) if err != nil { return err @@ -160,7 +160,7 @@ func (g *geoIPDatIn) walkRemoteFile(url string, entries map[string]*lib.Entry) e return nil } -func (g *geoIPDatIn) generateEntries(reader io.Reader, entries map[string]*lib.Entry) error { +func (g *GeoIPDatIn) generateEntries(reader io.Reader, entries map[string]*lib.Entry) error { geoipBytes, err := io.ReadAll(reader) if err != nil { return err diff --git a/plugin/v2ray/dat_out.go b/plugin/v2ray/dat_out.go index 3b120277..3e1cdbda 100644 --- a/plugin/v2ray/dat_out.go +++ b/plugin/v2ray/dat_out.go @@ -16,8 +16,8 @@ import ( ) const ( - typeGeoIPdatOut = "v2rayGeoIPDat" - descGeoIPdatOut = "Convert data to V2Ray GeoIP dat format" + TypeGeoIPdatOut = "v2rayGeoIPDat" + DescGeoIPdatOut = "Convert data to V2Ray GeoIP dat format" ) var ( @@ -26,11 +26,11 @@ var ( ) func init() { - lib.RegisterOutputConfigCreator(typeGeoIPdatOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { + lib.RegisterOutputConfigCreator(TypeGeoIPdatOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { return newGeoIPDat(action, data) }) - lib.RegisterOutputConverter(typeGeoIPdatOut, &geoIPDatOut{ - Description: descGeoIPdatOut, + lib.RegisterOutputConverter(TypeGeoIPdatOut, &GeoIPDatOut{ + Description: DescGeoIPdatOut, }) } @@ -58,10 +58,10 @@ func newGeoIPDat(action lib.Action, data json.RawMessage) (lib.OutputConverter, tmp.OutputDir = defaultOutputDir } - return &geoIPDatOut{ - Type: typeGeoIPdatOut, + return &GeoIPDatOut{ + Type: TypeGeoIPdatOut, Action: action, - Description: descGeoIPdatOut, + Description: DescGeoIPdatOut, OutputName: tmp.OutputName, OutputDir: tmp.OutputDir, Want: tmp.Want, @@ -71,7 +71,7 @@ func newGeoIPDat(action lib.Action, data json.RawMessage) (lib.OutputConverter, }, nil } -type geoIPDatOut struct { +type GeoIPDatOut struct { Type string Action lib.Action Description string @@ -83,19 +83,19 @@ type geoIPDatOut struct { OnlyIPType lib.IPType } -func (g *geoIPDatOut) GetType() string { +func (g *GeoIPDatOut) GetType() string { return g.Type } -func (g *geoIPDatOut) GetAction() lib.Action { +func (g *GeoIPDatOut) GetAction() lib.Action { return g.Action } -func (g *geoIPDatOut) GetDescription() string { +func (g *GeoIPDatOut) GetDescription() string { return g.Description } -func (g *geoIPDatOut) Output(container lib.Container) error { +func (g *GeoIPDatOut) Output(container lib.Container) error { geoIPList := new(GeoIPList) geoIPList.Entry = make([]*GeoIP, 0, 300) updated := false @@ -145,7 +145,7 @@ func (g *geoIPDatOut) Output(container lib.Container) error { return nil } -func (g *geoIPDatOut) filterAndSortList(container lib.Container) []string { +func (g *GeoIPDatOut) filterAndSortList(container lib.Container) []string { excludeMap := make(map[string]bool) for _, exclude := range g.Exclude { if exclude = strings.ToUpper(strings.TrimSpace(exclude)); exclude != "" { @@ -181,7 +181,7 @@ func (g *geoIPDatOut) filterAndSortList(container lib.Container) []string { return list } -func (g *geoIPDatOut) generateGeoIP(entry *lib.Entry) (*GeoIP, error) { +func (g *GeoIPDatOut) generateGeoIP(entry *lib.Entry) (*GeoIP, error) { var entryCidr []netip.Prefix var err error switch g.OnlyIPType { @@ -215,13 +215,13 @@ func (g *geoIPDatOut) generateGeoIP(entry *lib.Entry) (*GeoIP, error) { } // Sort by country code to make reproducible builds -func (g *geoIPDatOut) sort(list *GeoIPList) { +func (g *GeoIPDatOut) sort(list *GeoIPList) { sort.SliceStable(list.Entry, func(i, j int) bool { return list.Entry[i].CountryCode < list.Entry[j].CountryCode }) } -func (g *geoIPDatOut) writeFile(filename string, geoIPBytes []byte) error { +func (g *GeoIPDatOut) writeFile(filename string, geoIPBytes []byte) error { if err := os.MkdirAll(g.OutputDir, 0755); err != nil { return err } |
