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/maxmind | |
| parent | 1e26c9803d42d3601c75c4db2ee3ff565b6388d8 (diff) | |
Feat: export input & output converters
Diffstat (limited to 'plugin/maxmind')
| -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 |
4 files changed, 60 insertions, 60 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 } |
