forked from slackhq/go-audit
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathextras.go
35 lines (28 loc) · 819 Bytes
/
extras.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 main
import "github.com/spf13/viper"
var extraParserConstructors = []func(config *viper.Viper) (ExtraParser, error){}
type ExtraParser interface {
Parse(am *AuditMessage)
}
type ExtraParsers []ExtraParser
func RegisterExtraParser(constructor func(config *viper.Viper) (ExtraParser, error)) {
extraParserConstructors = append(extraParserConstructors, constructor)
}
func createExtraParsers(config *viper.Viper) ExtraParsers {
var extraParsers ExtraParsers
for _, constructor := range extraParserConstructors {
cp, err := constructor(config)
if err != nil {
el.Fatalf("Failed to create ExtraParser: %v", err)
}
if cp != nil {
extraParsers = append(extraParsers, cp)
}
}
return extraParsers
}
func (ps ExtraParsers) Parse(am *AuditMessage) {
for _, p := range ps {
p.Parse(am)
}
}