-
Notifications
You must be signed in to change notification settings - Fork 12
/
leaf.go
56 lines (47 loc) · 1 KB
/
leaf.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
package main
import (
"github.com/name5566/leaf/cluster"
"github.com/name5566/leaf/conf"
"github.com/name5566/leaf/console"
"github.com/name5566/leaf/log"
"github.com/name5566/leaf/module"
"os"
"os/signal"
"leaf_server/oss"
)
func Run(mods ...module.Module) {
// logger
if conf.LogLevel != "" {
logger, err := log.New(conf.LogLevel, conf.LogPath, conf.LogFlag)
if err != nil {
panic(err)
}
log.Export(logger)
defer logger.Close()
}
osslogger, err := oss.NewLogger("udp", conf.OssLogAddr, "test")
if nil != err {
log.Error("init oss logger failed:", err.Error())
return
}
oss.Export(osslogger)
defer oss.Close()
log.Release("starting up")
// module
for i := 0; i < len(mods); i++ {
module.Register(mods[i])
}
module.Init()
// cluster
cluster.Init()
// console
console.Init()
// close
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill)
sig := <-c
log.Release("closing down (signal: %v)", sig)
console.Destroy()
cluster.Destroy()
module.Destroy()
}