-
Notifications
You must be signed in to change notification settings - Fork 19
/
main.go
73 lines (53 loc) · 1.27 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
72
73
package main
import (
"os"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v3"
"github.com/serfreeman1337/asterlink/connect"
)
type newConnectorFunc func([]byte) (connect.Connecter, error)
var connectors []newConnectorFunc
func main() {
log.SetFormatter(&log.TextFormatter{})
log.SetOutput(os.Stdout)
log.Info("AsterLink")
var amiCfg AmiConfig
var connector connect.Connecter
if cfgBytes, err := os.ReadFile("conf.yml"); err == nil {
var config struct {
LogLevel log.Level `yaml:"log_level"`
}
if err := yaml.Unmarshal(cfgBytes, &config); err != nil {
log.Fatal(err)
}
if err := yaml.Unmarshal(cfgBytes, &amiCfg); err != nil {
log.Fatal(err)
}
log.WithField("level", config.LogLevel).Info("Setting log level")
log.SetLevel(config.LogLevel)
for _, getConnector := range connectors {
if connector, err = getConnector(cfgBytes); err != nil {
log.Fatal(err)
}
if connector != nil {
break
}
}
} else {
log.Fatal(err)
}
if connector == nil {
log.Warn("No connector selected")
connector = connect.NewDummyConnector()
}
ami, err := NewAmiConnector(&amiCfg)
if err != nil {
log.Fatal(err)
}
connector.SetOriginate(ami.Originate)
connector.Init()
ami.SetConnector(connector)
ami.Init()
r := make(chan bool)
<-r
}