forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
35 lines (27 loc) · 944 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package harvester
import (
"regexp"
"time"
"github.com/elastic/beats/filebeat/harvester/processor"
"github.com/elastic/beats/libbeat/common"
)
// 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
}
// 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
}