1 Star 0 Fork 0

zhangjungang/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
util.go 1.34 KB
一键复制 编辑 原始数据 按行查看 历史
Tudor Golubenco 提交于 2016-03-12 07:38 +08:00 . JSON support
package harvester
import (
"regexp"
"time"
"github.com/elastic/beats/filebeat/harvester/processor"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
)
// readLine reads a full line into buffer and returns it.
// In case of partial lines, readLine does return and error and en empty string
// This could potentialy be improved / replaced by https://github.com/elastic/beats/libbeat/tree/master/common/streambuf
func readLine(reader processor.LineProcessor) (time.Time, string, int, common.MapStr, error) {
l, err := reader.Next()
// Full line read to be returned
if l.Bytes != 0 && err == nil {
return l.Ts, string(l.Content), l.Bytes, l.Fields, err
}
return time.Time{}, "", 0, nil, err
}
// InitRegexps initializes a list of compiled regular expressions.
func InitRegexps(exprs []string) ([]*regexp.Regexp, error) {
result := []*regexp.Regexp{}
for _, exp := range exprs {
rexp, err := regexp.CompilePOSIX(exp)
if err != nil {
logp.Err("Fail to compile the regexp %s: %s", exp, err)
return nil, err
}
result = append(result, rexp)
}
return result, nil
}
// MatchAnyRegexps checks if the text matches any of the regular expressions
func MatchAnyRegexps(regexps []*regexp.Regexp, text string) bool {
for _, rexp := range regexps {
if rexp.MatchString(text) {
return true
}
}
return false
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangjungang/beats.git
git@gitee.com:zhangjungang/beats.git
zhangjungang
beats
beats
v5.0.0-alpha1

搜索帮助