-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
76 lines (57 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"flag"
"log"
"os"
"os/signal"
"syscall"
"time"
"github.com/kycklingar/pultimad/config"
"github.com/kycklingar/pultimad/daemon"
yp "github.com/kycklingar/pultimad/yiff.party"
)
type cfg struct {
YiffParty yp.Config
SleepTime time.Duration
}
func (c cfg) Default() config.Config {
c.YiffParty = c.YiffParty.Default().(yp.Config)
c.SleepTime = time.Second * 2
return c
}
func setupYP(conf config.Config) *yp.Checker {
var ypc = new(yp.Checker)
err := ypc.Init(conf)
if err != nil {
log.Fatal(err)
}
return ypc
}
func main() {
var conf cfg
var configFile = flag.String("cfg", "config.json", "Config file")
var configDefaults = flag.Bool("defaults", false, "Write a config file with default values")
flag.Parse()
if *configDefaults {
err := config.Write(*configFile, conf.Default())
if err != nil {
log.Fatal(err)
}
return
}
conf = conf.Default().(cfg)
err := config.Load(*configFile, &conf)
if err != nil {
log.Fatal(err)
}
err = config.Write(*configFile, conf)
if err != nil {
log.Fatal(err)
}
daemon := daemon.NewDaemon()
ypc := setupYP(conf.YiffParty)
daemon.RegisterDomain("yiff.party", ypc, conf.SleepTime)
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt, syscall.SIGINT)
daemon.Loop(quit)
}