-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
73 lines (64 loc) · 1.76 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
package main
import (
client "dzug/app/gateway/cmd"
commentservice "dzug/app/services/comment/cmd"
favorservice "dzug/app/services/favorite/cmd"
messageservice "dzug/app/services/message/cmd"
publishservice "dzug/app/services/publish/cmd"
relationservice "dzug/app/services/relation/cmd"
userservice "dzug/app/services/user/cmd"
"dzug/app/services/user/dal/redis"
"dzug/app/services/user/pkg/snowflake"
videoservice "dzug/app/services/video/cmd"
"dzug/conf"
transfer "dzug/conf/confagent/log_transfer"
"dzug/repo"
"fmt"
"time"
"go.uber.org/zap"
)
func main() {
//1. 初始化配置文件
if err := conf.Init(); err != nil {
fmt.Printf("Config file initialization error,%#v", err)
return
}
//2.初始化kafka消费者和ES
go transfer.Init()
//3. 初始化mysql数据库
if err := repo.Init(); err != nil {
fmt.Printf("mysql init error,%#v", err)
zap.L().Error("初始化mysql数据库失败!!!")
return
}
//defer repo.Close()
//4.初始化redis连接
if err := redis.Init(); err != nil {
fmt.Printf("init redis failed, err:%v\n", err)
return
}
// 程序退出关闭数据库连接
defer redis.Close()
//5. snowflake初始化
if err := snowflake.Init(conf.Config.StartTime, conf.Config.MachineID); err != nil {
zap.L().Error("snowflake initialization error", zap.Error(err))
return
}
//6.启动日志收集
go func() {
err := conf.Collectlog()
if err != nil {
zap.L().Error("log collect error ,", zap.Error(err))
}
}()
//6.启动服务(后续可将所有的服务单独写到一个文件)
go userservice.Start()
time.Sleep(time.Second)
go videoservice.Start()
go favorservice.Start()
go messageservice.Start()
go commentservice.Start()
go relationservice.Start()
go publishservice.Start()
client.Start()
}