-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.go
55 lines (46 loc) · 958 Bytes
/
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
package main
import (
"fmt"
"log"
"os"
"os/signal"
"syscall"
"github.com/BurntSushi/toml"
)
// Config holds the runtime configuration for this program. It is parsed
// from a TOML file on startup.
type Config struct {
Asterisk struct {
Host string
Port int
Username string
Password string
}
Zammad struct {
Endpoint string
Token string
}
}
var config = Config{}
func main() {
if len(os.Args) < 2 {
fmt.Println("usage:", os.Args[0], "path/to/config.cfg")
os.Exit(1)
}
// Configure log format
flags := log.Lshortfile
if os.Getenv("JOURNAL_STREAM") == "" {
// not running as systemd service, add timestamps
flags |= log.LstdFlags
}
log.SetFlags(flags)
// Parse config file
if _, err := toml.DecodeFile(os.Args[1], &config); err != nil {
log.Fatal(err)
}
startAsterisk()
// Wait for SIGINT or SIGTERM
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
<-sigs
}