-
Notifications
You must be signed in to change notification settings - Fork 3
/
read.go
46 lines (36 loc) · 990 Bytes
/
read.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
36
37
38
39
40
41
42
43
44
45
46
package logfrog
import (
"encoding/json"
)
type ReaderType string
const (
ReaderTypePlain ReaderType = ""
ReaderTypeDockerCompose ReaderType = "docker-compose"
ReaderTypeStern ReaderType = "stern"
ReaderTypeGograpple ReaderType = "gograpple"
)
func GetAvailableTypes() []ReaderType {
return []ReaderType{ReaderTypeDockerCompose, ReaderTypeStern, ReaderTypeGograpple}
}
type LogData map[string]interface{}
type LogReader interface {
Valid(line string) bool
Read(line string) (label string, logData LogData, err error)
}
type ReaderPlain struct{}
func (pr *ReaderPlain) Valid(line string) bool {
return line != ""
}
func (pr *ReaderPlain) Read(line string) (label string, logData LogData, err error) {
return read(line)
}
// Read read a json log line
func read(line string) (label string, logData LogData, errRead error) {
label = ""
errParse := json.Unmarshal([]byte(line), &logData)
if errParse != nil {
errRead = errParse
return
}
return
}