generated from CyanAsterisk/.github
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
77 lines (71 loc) · 2.47 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
74
75
76
77
package main
import (
"context"
"net"
"strconv"
"github.com/CyanAsterisk/TikGok/server/cmd/video/config"
"github.com/CyanAsterisk/TikGok/server/cmd/video/dao"
"github.com/CyanAsterisk/TikGok/server/cmd/video/initialize"
"github.com/CyanAsterisk/TikGok/server/cmd/video/pkg"
"github.com/CyanAsterisk/TikGok/server/shared/consts"
video "github.com/CyanAsterisk/TikGok/server/shared/kitex_gen/video/videoservice"
"github.com/cloudwego/kitex/pkg/klog"
"github.com/cloudwego/kitex/pkg/limit"
"github.com/cloudwego/kitex/pkg/rpcinfo"
"github.com/cloudwego/kitex/pkg/utils"
"github.com/cloudwego/kitex/server"
"github.com/kitex-contrib/obs-opentelemetry/provider"
"github.com/kitex-contrib/obs-opentelemetry/tracing"
)
func main() {
// initialization
initialize.InitLogger()
IP, Port := initialize.InitFlag()
r, info := initialize.InitNacos(Port)
db := initialize.InitDB()
p := provider.NewOpenTelemetryProvider(
provider.WithServiceName(config.GlobalServerConfig.Name),
provider.WithExportEndpoint(config.GlobalServerConfig.OtelInfo.EndPoint),
provider.WithInsecure(),
)
defer p.Shutdown(context.Background())
rC := initialize.InitRedis()
amqpC := initialize.InitMq()
interactionC := initialize.InitInteraction()
userC := initialize.InitUser()
publisher, err := pkg.NewPublisher(amqpC, config.GlobalServerConfig.RabbitMqInfo.Exchange)
if err != nil {
klog.Fatal("cannot create publisher", err)
}
subscriber, err := pkg.NewSubscriber(amqpC, config.GlobalServerConfig.RabbitMqInfo.Exchange)
if err != nil {
klog.Fatal("cannot create subscriber", err)
}
videoDao := dao.NewVideo(db)
go func() {
err = pkg.SubscribeRoutine(subscriber, videoDao)
if err != nil {
klog.Fatal("subscribe err", err)
}
}()
impl := &VideoServiceImpl{
Publisher: publisher,
UserManager: &pkg.UserManager{UserService: userC},
InteractionManager: &pkg.InteractionManager{InteractionService: interactionC},
RedisManager: pkg.NewRedisManager(rC),
Dao: videoDao,
}
// Create new server.
srv := video.NewServer(impl,
server.WithServiceAddr(utils.NewNetAddr(consts.TCP, net.JoinHostPort(IP, strconv.Itoa(Port)))),
server.WithRegistry(r),
server.WithRegistryInfo(info),
server.WithLimit(&limit.Option{MaxConnections: 2000, MaxQPS: 500}),
server.WithSuite(tracing.NewServerSuite()),
server.WithServerBasicInfo(&rpcinfo.EndpointBasicInfo{ServiceName: config.GlobalServerConfig.Name}),
)
err = srv.Run()
if err != nil {
klog.Fatal(err)
}
}