forked from name5566/leaf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleaf.go
More file actions
54 lines (44 loc) · 1005 Bytes
/
leaf.go
File metadata and controls
54 lines (44 loc) · 1005 Bytes
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
package leaf
import (
"os"
"os/signal"
"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"
)
var serverName = ""
func RunWithName(name string, mods ...module.Module) {
serverName = name
Run(mods[:]...)
}
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()
}
// module
for i := 0; i < len(mods); i++ {
module.Register(mods[i])
}
module.Init()
// cluster
cluster.Init()
// console
console.Init()
log.Release(">>>>>>>>>>>>>>>> %s Leaf-%v starting up! <<<<<<<<<<<<<<<<<", serverName, version)
// close
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill)
sig := <-c
log.Release("Leaf closing down (signal: %v)", sig)
console.Destroy()
cluster.Destroy()
module.Destroy()
}