-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (54 loc) · 1.28 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
package main
import (
"bytes"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"time"
)
func fakeConfig() {
viper.SetConfigType("yaml") // or viper.SetConfigType("YAML")
// any approach to require this configuration into your program.
var yamlExample = []byte(`
monitors:
file:
local:
name: "Local file"
description: "Some local file description"
path: /tmp/test
rule:
regex: '^[A-Z]+\\.com$
invert: true
dummy:
fake:
name: "Fake monitor"
is_safe: true
`)
viper.ReadConfig(bytes.NewBuffer(yamlExample))
}
func main() {
viper.SetConfigName("barn")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
viper.SetDefault("discovery.port", 32227)
viper.SetDefault("api.port", 8080)
viper.ReadInConfig()
log.SetFormatter(&log.TextFormatter{})
//fakeConfig()
//if err != nil {
// panic(fmt.Errorf("fatal error config file: %w", err))
//}
barnSrv := New()
mCfg := viper.GetViper()
barnSrv.LoadMonitorsFromConfig(mCfg)
apiPort := viper.GetUint32("api.port")
discoveryPort := viper.GetUint32("discovery.port")
discovery := NewDiscoverySever(discoveryPort, apiPort)
api := NewApiServer(barnSrv, apiPort)
go discovery.Start()
defer discovery.Close()
go api.Start()
for {
barnSrv.Refresh()
time.Sleep(10 * time.Second)
}
}