logmania/input/all/internal.go

47 lines
807 B
Go
Raw Normal View History

2018-09-05 01:53:23 +02:00
package all
import (
2019-06-20 09:25:43 +02:00
"github.com/bdlm/log"
2018-09-05 01:53:23 +02:00
"dev.sum7.eu/genofire/logmania/input"
)
type Input struct {
input.Input
list []input.Input
}
func Init(configInterface interface{}, exportChannel chan *log.Entry) input.Input {
config := configInterface.(map[string]interface{})
var list []input.Input
for inputType, init := range input.Register {
configForItem := config[inputType]
if configForItem == nil {
2018-09-05 21:00:02 +02:00
log.Warnf("the input type '%s' has no configuration", inputType)
2018-09-05 01:53:23 +02:00
continue
}
2018-09-05 21:00:02 +02:00
in := init(configForItem, exportChannel)
2018-09-05 01:53:23 +02:00
2018-09-05 21:00:02 +02:00
if in == nil {
2018-09-05 01:53:23 +02:00
continue
}
2018-09-05 21:00:02 +02:00
list = append(list, in)
2018-09-05 01:53:23 +02:00
}
return &Input{
list: list,
}
}
func (in *Input) Listen() {
for _, item := range in.list {
go item.Listen()
}
}
func (in *Input) Close() {
for _, item := range in.list {
item.Close()
}
}