@@ -2,36 +2,53 @@ package filter
import (
"strconv"
"unsafe"
"github.com/childe/gohangout/value_render"
"github.com/golang/glog"
datx "github.com/ipipdotnet/datx-go"
ipdb "github.com/ipipdotnet/ipdb-go"
)
type IPIPFilter struct {
config map[interface{}]interface{}
src string
srcVR value_render.ValueRender
target string
data_type string
language string
database string
city *datx.City
city unsafe.Pointer
overwrite bool
}
func (l *MethodLibrary) NewIPIPFilter(config map[interface{}]interface{}) *IPIPFilter {
plugin := &IPIPFilter{
config: config,
target: "geoip",
data_type: "datx",
language: "CN",
overwrite: true,
}
if overwrite, ok := config["overwrite"]; ok {
plugin.overwrite = overwrite.(bool)
}
if data_type, ok := config["type"]; ok {
plugin.data_type = data_type.(string)
}
if language, ok := config["language"]; ok {
plugin.language = language.(string)
}
if database, ok := config["database"]; ok {
plugin.database = database.(string)
city, err := datx.NewCity(plugin.database)
var city unsafe.Pointer
var err error
if plugin.data_type == "datx" {
*city, err = datx.NewCity(plugin.database)
} else {
*city, err = ipdb.NewCity(plugin.database)
}
if err != nil {
glog.Fatalf("could not load %s: %s", plugin.database, err)
} else {
@@ -59,8 +76,15 @@ func (plugin *IPIPFilter) Filter(event map[string]interface{}) (map[string]inter
if inputI == nil {
return event, false
}
a, err := plugin.city.Find(inputI.(string))
var a []string
var err error
if plugin.data_type == "datx" {
city := (*datx.City)(plugin.city)
a, err = city.Find(inputI.(string))
} else {
city := (*ipdb.City)(plugin.city)
a, err = city.Find(inputI.(string), plugin.language)
}
if err != nil {
glog.V(10).Infof("failed to find %s: %s", inputI.(string), err)
return event, false
ipip支持ipdb文件 · childe/gohangout@bd8bc64 · GitHub
相关链接
- Hangout with ClickHouse
- 华为p50pro可以用谷歌服务吗
- 华为mate30pro怎么安装gms框架
- Kafka 故障恢复后不能恢复消费,刷报错,重启后从最新开始读 · Issue #82 · childe/gohangout · GitHub
- [Clickhouse Output] WaitGroup is reused before previous Wait has returned · Issue #119 · childe/gohangout · GitHub
- my kafka version is 1.0.0,kafka server got the err:Magic v0 does not support record headers · Issue #21 · childe/gohangout · GitHub