-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (45 loc) · 1.02 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
package main
import (
"flag"
"io"
"log"
"os"
"github.com/lwwgo/goraft/server"
"github.com/spf13/viper"
)
func main() {
configName := flag.String("c", "conf.toml", "conf")
flag.Parse()
f, err := os.OpenFile("log/"+*configName+".log", os.O_CREATE|os.O_RDWR|os.O_TRUNC, os.ModePerm)
if err != nil {
return
}
defer f.Close()
// 日志同时输出到终端和文件
multiWriter := io.MultiWriter(os.Stdout, f)
log.SetOutput(multiWriter)
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
var config server.Config
curPath, err := os.Getwd()
if err != nil {
return
}
vip := viper.New()
vip.AddConfigPath(curPath + "/conf")
vip.SetConfigName(*configName)
vip.SetConfigType("toml")
if err := vip.ReadInConfig(); err != nil {
panic(err)
}
if err := vip.Unmarshal(&config); err != nil {
panic(err)
}
log.Printf("config %+v\n", config)
log.Printf("start raft clueter!\n")
rfNode, err := server.InitServer(config)
if err != nil {
panic(err)
}
rfNode.Run()
defer log.Printf("exist raft clueter!\n")
}