forked from emitter-io/emitter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
43 lines (35 loc) · 1 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
package main
import (
"math/rand"
"os"
"time"
"github.com/emitter-io/emitter/config"
"github.com/emitter-io/emitter/emitter"
"github.com/emitter-io/emitter/logging"
"github.com/emitter-io/emitter/network/address"
"github.com/emitter-io/emitter/security"
"github.com/emitter-io/emitter/utils"
)
func main() {
logging.SetWriter(os.Stdout, true)
// Parse the configuration
cfg, err := config.ReadOrCreate("emitter.conf", security.NewEnvironmentProvider(), security.NewVaultProvider(address.Fingerprint()))
if err != nil {
panic("Unable to parse configuration, due to " + err.Error())
}
// Setup the new service
svc, err := emitter.NewService(cfg)
if err != nil {
panic(err.Error())
}
// Flush the log
utils.Repeat(func() {
if err := logging.Flush(); err != nil {
println("Unable to flush logger, due to " + err.Error())
}
}, 100*time.Millisecond, svc.Closing)
// Initialize the rand function for key generation.
rand.Seed(time.Now().UTC().UnixNano())
// Listen and serve
svc.Listen()
}