-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
72 lines (62 loc) · 1.64 KB
/
server.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
package main
import (
"account-auth-service/api"
"account-auth-service/logic"
"flag"
"fmt"
"github.com/donnie4w/go-logger/logger"
"gitlab.ucloudadmin.com/peter/ugo/common"
"net/http"
"runtime"
"strconv"
"time"
)
var (
confFile = flag.String("c", "", "configuration file,json format")
)
func main() {
runtime.GOMAXPROCS(0)
// 解释命令行选项
common.ProcessOptions()
if err := common.LoadConfigFromFile(*confFile); err != nil {
fmt.Println("Load Config File fail,", err)
return
}
common.DumpConfigContent()
//初始化日志
dir, _ := common.GetConfigByKey("log.dir")
name, _ := common.GetConfigByKey("log.name")
//size, _ := common.GetConfigByKey("log.maxSize")
//files, _ := common.GetConfigByKey("log.maxFiles")
level, _ := common.GetConfigByKey("log.level")
logger.SetRollingDaily(dir.(string), name.(string))
//logger.SetRollingFile(dir.(string), name.(string), int32(files.(float64)), int64(size.(float64)), logger.MB)
logger.SetLevel(logger.LEVEL(level.(float64)))
//初始化数据库
err := logic.NewDBRegist()
if err != nil {
fmt.Println("init DB error:", err)
return
}
// 获取监听ip
ip, err := common.GetConfigByKey("addr.ip")
if err != nil {
fmt.Println("can not get listen ip:", err)
return
}
ipAddr, _ := ip.(string)
// 获取监听端口
port, err := common.GetConfigByKey("addr.port")
if err != nil {
fmt.Println("can not get listen port")
return
}
fmt.Println(time.Now().Unix())
addr := string(ipAddr) + ":" + strconv.Itoa(int(port.(float64)))
fmt.Println(addr)
logger.Debug("This is a test")
err = http.ListenAndServe(addr, api.WsContainer)
if err != nil {
fmt.Println(err)
}
}