summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoropenai-code-agent[bot] <[email protected]>2026-04-28 17:48:08 +0000
committerGitHub <[email protected]>2026-04-28 17:48:08 +0000
commitbf3a08f53f060f9ff3503d204f9dc15cee0ff2a5 (patch)
treecdc7dc6acdeaca6d5185f1b1824e332bfc982caf
parente25f9fcf96d9971e90c3a5df9087d882e4a997a7 (diff)
refactor(maxmind): use functional options for mmdb/csv pluginscodex/refactor-plugins-functional-options
Co-authored-by: Loyalsoldier <[email protected]>
-rw-r--r--plugin/maxmind/common_in.go55
-rw-r--r--plugin/maxmind/common_out.go118
-rw-r--r--plugin/maxmind/dbip_country_mmdb_in.go2
-rw-r--r--plugin/maxmind/dbip_country_mmdb_out.go2
-rw-r--r--plugin/maxmind/ipinfo_country_mmdb_in.go2
-rw-r--r--plugin/maxmind/ipinfo_country_mmdb_out.go2
-rw-r--r--plugin/maxmind/maxmind_asn_csv_in.go121
-rw-r--r--plugin/maxmind/maxmind_country_csv_in.go107
-rw-r--r--plugin/maxmind/maxmind_country_mmdb_in.go18
-rw-r--r--plugin/maxmind/maxmind_country_mmdb_out.go2
10 files changed, 309 insertions, 120 deletions
diff --git a/plugin/maxmind/common_in.go b/plugin/maxmind/common_in.go
index 3d97388c..1f2db85d 100644
--- a/plugin/maxmind/common_in.go
+++ b/plugin/maxmind/common_in.go
@@ -2,19 +2,48 @@ package maxmind
import (
"encoding/json"
+ "log"
"path/filepath"
"strings"
"github.com/Loyalsoldier/geoip/lib"
)
+func WithMMDBInURI(uri string) lib.InputOption {
+ return func(c lib.InputConverter) {
+ uri = strings.TrimSpace(uri)
+ if uri == "" {
+ log.Fatalf("❌ [type %s | action %s] missing uri", c.GetType(), c.GetAction())
+ }
+ c.(*GeoLite2CountryMMDBIn).URI = uri
+ }
+}
+
+func WithMMDBInWantedList(lists []string) lib.InputOption {
+ return func(c lib.InputConverter) {
+ wantList := make(map[string]bool)
+ for _, want := range lists {
+ if want = strings.ToUpper(strings.TrimSpace(want)); want != "" {
+ wantList[want] = true
+ }
+ }
+ c.(*GeoLite2CountryMMDBIn).Want = wantList
+ }
+}
+
+func WithMMDBInOnlyIPType(onlyIPType lib.IPType) lib.InputOption {
+ return func(c lib.InputConverter) {
+ c.(*GeoLite2CountryMMDBIn).OnlyIPType = onlyIPType
+ }
+}
+
var (
defaultGeoLite2CountryMMDBFile = filepath.Join("./", "geolite2", "GeoLite2-Country.mmdb")
defaultDBIPCountryMMDBFile = filepath.Join("./", "db-ip", "dbip-country-lite.mmdb")
defaultIPInfoCountryMMDBFile = filepath.Join("./", "ipinfo", "country.mmdb")
)
-func newGeoLite2CountryMMDBIn(iType string, iDesc string, action lib.Action, data json.RawMessage) (lib.InputConverter, error) {
+func NewGeoLite2CountryMMDBInFromBytes(iType string, iDesc string, action lib.Action, data []byte) (lib.InputConverter, error) {
var tmp struct {
URI string `json:"uri"`
Want []string `json:"wantedList"`
@@ -40,20 +69,12 @@ func newGeoLite2CountryMMDBIn(iType string, iDesc string, action lib.Action, dat
}
}
- // Filter want list
- wantList := make(map[string]bool)
- for _, want := range tmp.Want {
- if want = strings.ToUpper(strings.TrimSpace(want)); want != "" {
- wantList[want] = true
- }
- }
-
- return &GeoLite2CountryMMDBIn{
- Type: iType,
- Action: action,
- Description: iDesc,
- URI: tmp.URI,
- Want: wantList,
- OnlyIPType: tmp.OnlyIPType,
- }, nil
+ return NewGeoLite2CountryMMDBIn(
+ iType,
+ iDesc,
+ action,
+ WithMMDBInURI(tmp.URI),
+ WithMMDBInWantedList(tmp.Want),
+ WithMMDBInOnlyIPType(tmp.OnlyIPType),
+ ), nil
}
diff --git a/plugin/maxmind/common_out.go b/plugin/maxmind/common_out.go
index 21063faa..1b0c036f 100644
--- a/plugin/maxmind/common_out.go
+++ b/plugin/maxmind/common_out.go
@@ -12,6 +12,80 @@ import (
"github.com/oschwald/maxminddb-golang/v2"
)
+func NewGeoLite2CountryMMDBOut(iType string, iDesc string, action lib.Action, opts ...lib.OutputOption) lib.OutputConverter {
+ g := &GeoLite2CountryMMDBOut{
+ Type: iType,
+ Action: action,
+ Description: iDesc,
+ OutputName: defaultGeoLite2CountryMMDBOutputName,
+ }
+
+ switch iType {
+ case TypeGeoLite2CountryMMDBOut:
+ g.OutputDir = defaultMaxmindOutputDir
+ case TypeDBIPCountryMMDBOut:
+ g.OutputDir = defaultDBIPOutputDir
+ case TypeIPInfoCountryMMDBOut:
+ g.OutputDir = defaultIPInfoOutputDir
+ }
+
+ for _, opt := range opts {
+ if opt != nil {
+ opt(g)
+ }
+ }
+
+ return g
+}
+
+func WithMMDBOutOutputName(name string) lib.OutputOption {
+ return func(c lib.OutputConverter) {
+ name = strings.TrimSpace(name)
+ if name != "" {
+ c.(*GeoLite2CountryMMDBOut).OutputName = name
+ }
+ }
+}
+
+func WithMMDBOutOutputDir(dir string) lib.OutputOption {
+ return func(c lib.OutputConverter) {
+ dir = strings.TrimSpace(dir)
+ if dir != "" {
+ c.(*GeoLite2CountryMMDBOut).OutputDir = dir
+ }
+ }
+}
+
+func WithMMDBOutWantedList(lists []string) lib.OutputOption {
+ return func(c lib.OutputConverter) {
+ c.(*GeoLite2CountryMMDBOut).Want = lists
+ }
+}
+
+func WithMMDBOutOverwriteList(lists []string) lib.OutputOption {
+ return func(c lib.OutputConverter) {
+ c.(*GeoLite2CountryMMDBOut).Overwrite = lists
+ }
+}
+
+func WithMMDBOutExcludedList(lists []string) lib.OutputOption {
+ return func(c lib.OutputConverter) {
+ c.(*GeoLite2CountryMMDBOut).Exclude = lists
+ }
+}
+
+func WithMMDBOutOnlyIPType(onlyIPType lib.IPType) lib.OutputOption {
+ return func(c lib.OutputConverter) {
+ c.(*GeoLite2CountryMMDBOut).OnlyIPType = onlyIPType
+ }
+}
+
+func WithMMDBOutSourceMMDBURI(uri string) lib.OutputOption {
+ return func(c lib.OutputConverter) {
+ c.(*GeoLite2CountryMMDBOut).SourceMMDBURI = uri
+ }
+}
+
var (
defaultGeoLite2CountryMMDBOutputName = "Country.mmdb"
@@ -100,7 +174,7 @@ func (d dbipCountry) HasData() bool {
return d != zeroDBIPCountry
}
-func newGeoLite2CountryMMDBOut(iType string, iDesc string, action lib.Action, data json.RawMessage) (lib.OutputConverter, error) {
+func NewGeoLite2CountryMMDBOutFromBytes(iType string, iDesc string, action lib.Action, data []byte) (lib.OutputConverter, error) {
var tmp struct {
OutputName string `json:"outputName"`
OutputDir string `json:"outputDir"`
@@ -118,36 +192,18 @@ func newGeoLite2CountryMMDBOut(iType string, iDesc string, action lib.Action, da
}
}
- if tmp.OutputName == "" {
- tmp.OutputName = defaultGeoLite2CountryMMDBOutputName
- }
-
- if tmp.OutputDir == "" {
- switch iType {
- case TypeGeoLite2CountryMMDBOut:
- tmp.OutputDir = defaultMaxmindOutputDir
-
- case TypeDBIPCountryMMDBOut:
- tmp.OutputDir = defaultDBIPOutputDir
-
- case TypeIPInfoCountryMMDBOut:
- tmp.OutputDir = defaultIPInfoOutputDir
- }
- }
-
- return &GeoLite2CountryMMDBOut{
- Type: iType,
- Action: action,
- Description: iDesc,
- OutputName: tmp.OutputName,
- OutputDir: tmp.OutputDir,
- Want: tmp.Want,
- Overwrite: tmp.Overwrite,
- Exclude: tmp.Exclude,
- OnlyIPType: tmp.OnlyIPType,
-
- SourceMMDBURI: tmp.SourceMMDBURI,
- }, nil
+ return NewGeoLite2CountryMMDBOut(
+ iType,
+ iDesc,
+ action,
+ WithMMDBOutOutputName(tmp.OutputName),
+ WithMMDBOutOutputDir(tmp.OutputDir),
+ WithMMDBOutWantedList(tmp.Want),
+ WithMMDBOutOverwriteList(tmp.Overwrite),
+ WithMMDBOutExcludedList(tmp.Exclude),
+ WithMMDBOutOnlyIPType(tmp.OnlyIPType),
+ WithMMDBOutSourceMMDBURI(tmp.SourceMMDBURI),
+ ), nil
}
func (g *GeoLite2CountryMMDBOut) GetExtraInfo() (map[string]any, error) {
diff --git a/plugin/maxmind/dbip_country_mmdb_in.go b/plugin/maxmind/dbip_country_mmdb_in.go
index 304f29e5..aaaf34ae 100644
--- a/plugin/maxmind/dbip_country_mmdb_in.go
+++ b/plugin/maxmind/dbip_country_mmdb_in.go
@@ -18,7 +18,7 @@ const (
func init() {
lib.RegisterInputConfigCreator(TypeDBIPCountryMMDBIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) {
- return newGeoLite2CountryMMDBIn(TypeDBIPCountryMMDBIn, DescDBIPCountryMMDBIn, action, data)
+ return NewGeoLite2CountryMMDBInFromBytes(TypeDBIPCountryMMDBIn, DescDBIPCountryMMDBIn, action, data)
})
lib.RegisterInputConverter(TypeDBIPCountryMMDBIn, &GeoLite2CountryMMDBIn{
Description: DescDBIPCountryMMDBIn,
diff --git a/plugin/maxmind/dbip_country_mmdb_out.go b/plugin/maxmind/dbip_country_mmdb_out.go
index 77857d95..f246abf2 100644
--- a/plugin/maxmind/dbip_country_mmdb_out.go
+++ b/plugin/maxmind/dbip_country_mmdb_out.go
@@ -18,7 +18,7 @@ const (
func init() {
lib.RegisterOutputConfigCreator(TypeDBIPCountryMMDBOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) {
- return newGeoLite2CountryMMDBOut(TypeDBIPCountryMMDBOut, DescDBIPCountryMMDBOut, action, data)
+ return NewGeoLite2CountryMMDBOutFromBytes(TypeDBIPCountryMMDBOut, DescDBIPCountryMMDBOut, action, data)
})
lib.RegisterOutputConverter(TypeDBIPCountryMMDBOut, &GeoLite2CountryMMDBOut{
Description: DescDBIPCountryMMDBOut,
diff --git a/plugin/maxmind/ipinfo_country_mmdb_in.go b/plugin/maxmind/ipinfo_country_mmdb_in.go
index 8551e453..4730d003 100644
--- a/plugin/maxmind/ipinfo_country_mmdb_in.go
+++ b/plugin/maxmind/ipinfo_country_mmdb_in.go
@@ -18,7 +18,7 @@ const (
func init() {
lib.RegisterInputConfigCreator(TypeIPInfoCountryMMDBIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) {
- return newGeoLite2CountryMMDBIn(TypeIPInfoCountryMMDBIn, DescIPInfoCountryMMDBIn, action, data)
+ return NewGeoLite2CountryMMDBInFromBytes(TypeIPInfoCountryMMDBIn, DescIPInfoCountryMMDBIn, action, data)
})
lib.RegisterInputConverter(TypeIPInfoCountryMMDBIn, &GeoLite2CountryMMDBIn{
Description: DescIPInfoCountryMMDBIn,
diff --git a/plugin/maxmind/ipinfo_country_mmdb_out.go b/plugin/maxmind/ipinfo_country_mmdb_out.go
index bed18af7..aec195ff 100644
--- a/plugin/maxmind/ipinfo_country_mmdb_out.go
+++ b/plugin/maxmind/ipinfo_country_mmdb_out.go
@@ -18,7 +18,7 @@ const (
func init() {
lib.RegisterOutputConfigCreator(TypeIPInfoCountryMMDBOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) {
- return newGeoLite2CountryMMDBOut(TypeIPInfoCountryMMDBOut, DescIPInfoCountryMMDBOut, action, data)
+ return NewGeoLite2CountryMMDBOutFromBytes(TypeIPInfoCountryMMDBOut, DescIPInfoCountryMMDBOut, action, data)
})
lib.RegisterOutputConverter(TypeIPInfoCountryMMDBOut, &GeoLite2CountryMMDBOut{
Description: DescIPInfoCountryMMDBOut,
diff --git a/plugin/maxmind/maxmind_asn_csv_in.go b/plugin/maxmind/maxmind_asn_csv_in.go
index d924e3f9..141b1a7d 100644
--- a/plugin/maxmind/maxmind_asn_csv_in.go
+++ b/plugin/maxmind/maxmind_asn_csv_in.go
@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io"
+ "log"
"os"
"path/filepath"
"strings"
@@ -24,76 +25,112 @@ var (
func init() {
lib.RegisterInputConfigCreator(TypeGeoLite2ASNCSVIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) {
- return newGeoLite2ASNCSVIn(action, data)
+ return NewGeoLite2ASNCSVInFromBytes(action, data)
})
lib.RegisterInputConverter(TypeGeoLite2ASNCSVIn, &GeoLite2ASNCSVIn{
Description: DescGeoLite2ASNCSVIn,
})
}
-func newGeoLite2ASNCSVIn(action lib.Action, data json.RawMessage) (lib.InputConverter, error) {
- var tmp struct {
- IPv4File string `json:"ipv4"`
- IPv6File string `json:"ipv6"`
- Want lib.WantedListExtended `json:"wantedList"`
- OnlyIPType lib.IPType `json:"onlyIPType"`
+func NewGeoLite2ASNCSVIn(action lib.Action, opts ...lib.InputOption) lib.InputConverter {
+ g := &GeoLite2ASNCSVIn{
+ Type: TypeGeoLite2ASNCSVIn,
+ Action: action,
+ Description: DescGeoLite2ASNCSVIn,
}
- if len(data) > 0 {
- if err := json.Unmarshal(data, &tmp); err != nil {
- return nil, err
+ for _, opt := range opts {
+ if opt != nil {
+ opt(g)
}
}
- // When both of IP files are not specified,
- // it means user wants to use the default ones
- if tmp.IPv4File == "" && tmp.IPv6File == "" {
- tmp.IPv4File = defaultGeoLite2ASNCSVIPv4File
- tmp.IPv6File = defaultGeoLite2ASNCSVIPv6File
+ return g
+}
+
+func WithASNCSVIPv4File(path string) lib.InputOption {
+ return func(c lib.InputConverter) {
+ c.(*GeoLite2ASNCSVIn).IPv4File = strings.TrimSpace(path)
+ }
+}
+
+func WithASNCSVIPv6File(path string) lib.InputOption {
+ return func(c lib.InputConverter) {
+ c.(*GeoLite2ASNCSVIn).IPv6File = strings.TrimSpace(path)
}
+}
+
+func WithASNCSVWantedList(want lib.WantedListExtended) lib.InputOption {
+ return func(c lib.InputConverter) {
+ wantList := make(map[string][]string)
- // Filter want list
- wantList := make(map[string][]string) // map[asn][]listname or map[asn][]asn
+ for list, asnList := range want.TypeMap {
+ list = strings.ToUpper(strings.TrimSpace(list))
+ if list == "" {
+ continue
+ }
- for list, asnList := range tmp.Want.TypeMap {
- list = strings.ToUpper(strings.TrimSpace(list))
- if list == "" {
- continue
+ for _, asn := range asnList {
+ asn = strings.TrimPrefix(strings.ToLower(strings.TrimSpace(asn)), "as")
+ if asn == "" {
+ continue
+ }
+
+ wantList[asn] = append(wantList[asn], list)
+ }
}
- for _, asn := range asnList {
+ for _, asn := range want.TypeSlice {
asn = strings.TrimPrefix(strings.ToLower(strings.TrimSpace(asn)), "as")
if asn == "" {
continue
}
- if listArr, found := wantList[asn]; found {
- listArr = append(listArr, list)
- wantList[asn] = listArr
- } else {
- wantList[asn] = []string{list}
- }
+ wantList[asn] = []string{"AS" + asn}
}
+
+ c.(*GeoLite2ASNCSVIn).Want = wantList
+ }
+}
+
+func WithASNCSVOnlyIPType(onlyIPType lib.IPType) lib.InputOption {
+ return func(c lib.InputConverter) {
+ c.(*GeoLite2ASNCSVIn).OnlyIPType = onlyIPType
+ }
+}
+
+func NewGeoLite2ASNCSVInFromBytes(action lib.Action, data []byte) (lib.InputConverter, error) {
+ var tmp struct {
+ IPv4File string `json:"ipv4"`
+ IPv6File string `json:"ipv6"`
+ Want lib.WantedListExtended `json:"wantedList"`
+ OnlyIPType lib.IPType `json:"onlyIPType"`
}
- for _, asn := range tmp.Want.TypeSlice {
- asn = strings.TrimPrefix(strings.ToLower(strings.TrimSpace(asn)), "as")
- if asn == "" {
- continue
+ if len(data) > 0 {
+ if err := json.Unmarshal(data, &tmp); err != nil {
+ return nil, err
}
+ }
- wantList[asn] = []string{"AS" + asn}
+ // When both of IP files are not specified,
+ // it means user wants to use the default ones
+ if tmp.IPv4File == "" && tmp.IPv6File == "" {
+ tmp.IPv4File = defaultGeoLite2ASNCSVIPv4File
+ tmp.IPv6File = defaultGeoLite2ASNCSVIPv6File
}
- return &GeoLite2ASNCSVIn{
- Type: TypeGeoLite2ASNCSVIn,
- Action: action,
- Description: DescGeoLite2ASNCSVIn,
- IPv4File: tmp.IPv4File,
- IPv6File: tmp.IPv6File,
- Want: wantList,
- OnlyIPType: tmp.OnlyIPType,
- }, nil
+ if action != lib.ActionAdd && action != lib.ActionRemove {
+ log.Fatalf("❌ [type %s | action %s] invalid action", TypeGeoLite2ASNCSVIn, action)
+ }
+
+ return NewGeoLite2ASNCSVIn(
+ action,
+ WithASNCSVIPv4File(tmp.IPv4File),
+ WithASNCSVIPv6File(tmp.IPv6File),
+ WithASNCSVWantedList(tmp.Want),
+ WithASNCSVOnlyIPType(tmp.OnlyIPType),
+ ), nil
}
type GeoLite2ASNCSVIn struct {
diff --git a/plugin/maxmind/maxmind_country_csv_in.go b/plugin/maxmind/maxmind_country_csv_in.go
index 93d38c37..ccbd959f 100644
--- a/plugin/maxmind/maxmind_country_csv_in.go
+++ b/plugin/maxmind/maxmind_country_csv_in.go
@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io"
+ "log"
"os"
"path/filepath"
"strings"
@@ -25,14 +26,82 @@ var (
func init() {
lib.RegisterInputConfigCreator(TypeGeoLite2CountryCSVIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) {
- return newGeoLite2CountryCSVIn(action, data)
+ return NewGeoLite2CountryCSVInFromBytes(action, data)
})
lib.RegisterInputConverter(TypeGeoLite2CountryCSVIn, &GeoLite2CountryCSVIn{
Description: DescGeoLite2CountryCSVIn,
})
}
-func newGeoLite2CountryCSVIn(action lib.Action, data json.RawMessage) (lib.InputConverter, error) {
+func NewGeoLite2CountryCSVIn(action lib.Action, opts ...lib.InputOption) lib.InputConverter {
+ g := &GeoLite2CountryCSVIn{
+ Type: TypeGeoLite2CountryCSVIn,
+ Action: action,
+ Description: DescGeoLite2CountryCSVIn,
+ // defaults
+ CountryCodeFile: defaultGeoLite2CountryCodeFile,
+ IPv4File: defaultGeoLite2CountryIPv4File,
+ IPv6File: defaultGeoLite2CountryIPv6File,
+ }
+
+ for _, opt := range opts {
+ if opt != nil {
+ opt(g)
+ }
+ }
+
+ // If either IPv4/IPv6 explicitly cleared, keep the other.
+ // If both cleared, caller intended to clear both.
+ if g.IPv4File == defaultGeoLite2CountryIPv4File && g.IPv6File == "" {
+ g.IPv4File = ""
+ }
+ if g.IPv6File == defaultGeoLite2CountryIPv6File && g.IPv4File == "" {
+ g.IPv6File = ""
+ }
+
+ return g
+}
+
+func WithGeoLite2CountryCodeFile(path string) lib.InputOption {
+ return func(c lib.InputConverter) {
+ path = strings.TrimSpace(path)
+ if path != "" {
+ c.(*GeoLite2CountryCSVIn).CountryCodeFile = path
+ }
+ }
+}
+
+func WithGeoLite2CountryIPv4File(path string) lib.InputOption {
+ return func(c lib.InputConverter) {
+ c.(*GeoLite2CountryCSVIn).IPv4File = strings.TrimSpace(path)
+ }
+}
+
+func WithGeoLite2CountryIPv6File(path string) lib.InputOption {
+ return func(c lib.InputConverter) {
+ c.(*GeoLite2CountryCSVIn).IPv6File = strings.TrimSpace(path)
+ }
+}
+
+func WithGeoLite2CountryWantedList(lists []string) lib.InputOption {
+ return func(c lib.InputConverter) {
+ wantList := make(map[string]bool)
+ for _, want := range lists {
+ if want = strings.ToUpper(strings.TrimSpace(want)); want != "" {
+ wantList[want] = true
+ }
+ }
+ c.(*GeoLite2CountryCSVIn).Want = wantList
+ }
+}
+
+func WithGeoLite2CountryOnlyIPType(onlyIPType lib.IPType) lib.InputOption {
+ return func(c lib.InputConverter) {
+ c.(*GeoLite2CountryCSVIn).OnlyIPType = onlyIPType
+ }
+}
+
+func NewGeoLite2CountryCSVInFromBytes(action lib.Action, data []byte) (lib.InputConverter, error) {
var tmp struct {
CountryCodeFile string `json:"country"`
IPv4File string `json:"ipv4"`
@@ -47,35 +116,25 @@ func newGeoLite2CountryCSVIn(action lib.Action, data json.RawMessage) (lib.Input
}
}
- if tmp.CountryCodeFile == "" {
- tmp.CountryCodeFile = defaultGeoLite2CountryCodeFile
+ if action != lib.ActionAdd && action != lib.ActionRemove {
+ log.Fatalf("❌ [type %s | action %s] invalid action", TypeGeoLite2CountryCSVIn, action)
}
- // When both of IP files are not specified,
- // it means user wants to use the default ones
+ // Preserve old semantics: when both IPv4/IPv6 omitted, use defaults.
+ // When either specified, keep provided value (including empty string).
if tmp.IPv4File == "" && tmp.IPv6File == "" {
tmp.IPv4File = defaultGeoLite2CountryIPv4File
tmp.IPv6File = defaultGeoLite2CountryIPv6File
}
- // Filter want list
- wantList := make(map[string]bool)
- for _, want := range tmp.Want {
- if want = strings.ToUpper(strings.TrimSpace(want)); want != "" {
- wantList[want] = true
- }
- }
-
- return &GeoLite2CountryCSVIn{
- Type: TypeGeoLite2CountryCSVIn,
- Action: action,
- Description: DescGeoLite2CountryCSVIn,
- CountryCodeFile: tmp.CountryCodeFile,
- IPv4File: tmp.IPv4File,
- IPv6File: tmp.IPv6File,
- Want: wantList,
- OnlyIPType: tmp.OnlyIPType,
- }, nil
+ return NewGeoLite2CountryCSVIn(
+ action,
+ WithGeoLite2CountryCodeFile(tmp.CountryCodeFile),
+ WithGeoLite2CountryIPv4File(tmp.IPv4File),
+ WithGeoLite2CountryIPv6File(tmp.IPv6File),
+ WithGeoLite2CountryWantedList(tmp.Want),
+ WithGeoLite2CountryOnlyIPType(tmp.OnlyIPType),
+ ), nil
}
type GeoLite2CountryCSVIn struct {
diff --git a/plugin/maxmind/maxmind_country_mmdb_in.go b/plugin/maxmind/maxmind_country_mmdb_in.go
index 1f6d5386..9bf6413e 100644
--- a/plugin/maxmind/maxmind_country_mmdb_in.go
+++ b/plugin/maxmind/maxmind_country_mmdb_in.go
@@ -18,13 +18,29 @@ const (
func init() {
lib.RegisterInputConfigCreator(TypeGeoLite2CountryMMDBIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) {
- return newGeoLite2CountryMMDBIn(TypeGeoLite2CountryMMDBIn, DescGeoLite2CountryMMDBIn, action, data)
+ return NewGeoLite2CountryMMDBInFromBytes(TypeGeoLite2CountryMMDBIn, DescGeoLite2CountryMMDBIn, action, data)
})
lib.RegisterInputConverter(TypeGeoLite2CountryMMDBIn, &GeoLite2CountryMMDBIn{
Description: DescGeoLite2CountryMMDBIn,
})
}
+func NewGeoLite2CountryMMDBIn(iType string, iDesc string, action lib.Action, opts ...lib.InputOption) lib.InputConverter {
+ g := &GeoLite2CountryMMDBIn{
+ Type: iType,
+ Action: action,
+ Description: iDesc,
+ }
+
+ for _, opt := range opts {
+ if opt != nil {
+ opt(g)
+ }
+ }
+
+ return g
+}
+
type GeoLite2CountryMMDBIn struct {
Type string
Action lib.Action
diff --git a/plugin/maxmind/maxmind_country_mmdb_out.go b/plugin/maxmind/maxmind_country_mmdb_out.go
index fc72e83c..715f04d0 100644
--- a/plugin/maxmind/maxmind_country_mmdb_out.go
+++ b/plugin/maxmind/maxmind_country_mmdb_out.go
@@ -22,7 +22,7 @@ const (
func init() {
lib.RegisterOutputConfigCreator(TypeGeoLite2CountryMMDBOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) {
- return newGeoLite2CountryMMDBOut(TypeGeoLite2CountryMMDBOut, DescGeoLite2CountryMMDBOut, action, data)
+ return NewGeoLite2CountryMMDBOutFromBytes(TypeGeoLite2CountryMMDBOut, DescGeoLite2CountryMMDBOut, action, data)
})
lib.RegisterOutputConverter(TypeGeoLite2CountryMMDBOut, &GeoLite2CountryMMDBOut{
Description: DescGeoLite2CountryMMDBOut,