1 Star 0 Fork 0

sqos / beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
geolite.go 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
Steffen Siering 提交于 2016-10-24 10:46 . minor cleanups (#2819)
package common
import (
"os"
"path/filepath"
"github.com/elastic/beats/libbeat/logp"
"github.com/nranchev/go-libGeoIP"
)
// Geoip represents a string slice of GeoIP paths
type Geoip struct {
Paths *[]string
}
func LoadGeoIPData(config Geoip) *libgeo.GeoIP {
geoipPaths := []string{}
if config.Paths != nil {
geoipPaths = *config.Paths
}
if len(geoipPaths) == 0 {
// disabled
return nil
}
logp.Warn("GeoIP lookup support is deprecated and will be removed in version 6.0.")
// look for the first existing path
var geoipPath string
for _, path := range geoipPaths {
fi, err := os.Lstat(path)
if err != nil {
logp.Err("GeoIP path could not be loaded: %s", path)
continue
}
if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
// follow symlink
geoipPath, err = filepath.EvalSymlinks(path)
if err != nil {
logp.Warn("Could not load GeoIP data: %s", err.Error())
return nil
}
} else {
geoipPath = path
}
break
}
if len(geoipPath) == 0 {
logp.Warn("Couldn't load GeoIP database")
return nil
}
geoLite, err := libgeo.Load(geoipPath)
if err != nil {
logp.Warn("Could not load GeoIP data: %s", err.Error())
}
logp.Info("Loaded GeoIP data from: %s", geoipPath)
return geoLite
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sqos/beats.git
git@gitee.com:sqos/beats.git
sqos
beats
beats
v5.3.2

搜索帮助

344bd9b3 5694891 D2dac590 5694891