-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
71 lines (61 loc) · 1.32 KB
/
main.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"flag"
"io/ioutil"
"log"
"strings"
"github.com/BurntSushi/toml"
"github.com/yosisa/fluxion/buffer"
"github.com/yosisa/fluxion/engine"
)
var config struct {
Buffer []*buffer.Options
Input []map[string]interface{}
Filter []map[string]interface{}
}
func main() {
var configPath string
flag.StringVar(&configPath, "c", "/etc/fluxion.toml", "config file")
flag.Parse()
b, err := ioutil.ReadFile(configPath)
if err != nil {
log.Fatal("Failed to load config: ", err)
}
_, err = toml.Decode(string(b), &config)
if err != nil {
log.Fatal("Failed to load config: ", err)
}
eng := engine.New()
for _, bopts := range config.Buffer {
eng.RegisterBuffer(bopts)
}
for _, conf := range config.Input {
eng.RegisterInputPlugin(conf)
}
for _, conf := range config.Filter {
must(eng.RegisterFilterPlugin(conf))
}
// To support `output:...` form, re-decoding with relax type is needed.
var c map[string][]map[string]interface{}
toml.Decode(string(b), &c)
for k, v := range c {
keys := strings.SplitN(k, ":", 2)
if strings.ToLower(keys[0]) != "output" {
continue
}
var name string
if len(keys) == 2 {
name = keys[1]
}
for _, conf := range v {
must(eng.RegisterOutputPlugin(name, conf))
}
}
eng.Start()
eng.Wait()
}
func must(err error) {
if err != nil {
log.Fatal(err)
}
}