-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
56 lines (53 loc) · 1.62 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
package main
import (
"github.com/cloudwego/kitex/pkg/klog"
"github.com/cloudwego/kitex/pkg/limit"
"github.com/cloudwego/kitex/pkg/rpcinfo"
"github.com/cloudwego/kitex/server"
"github.com/hcdoit/tiktok/cmd/social/dal"
"github.com/hcdoit/tiktok/cmd/social/rpc"
"github.com/hcdoit/tiktok/kitex_gen/social/socialservice"
"github.com/hcdoit/tiktok/pkg/consts"
"github.com/hcdoit/tiktok/pkg/mw"
kitexlogrus "github.com/kitex-contrib/obs-opentelemetry/logging/logrus"
"github.com/kitex-contrib/obs-opentelemetry/provider"
"github.com/kitex-contrib/obs-opentelemetry/tracing"
etcd "github.com/kitex-contrib/registry-etcd"
"net"
)
func Init() {
dal.Init()
rpc.Init()
klog.SetLogger(kitexlogrus.NewLogger())
klog.SetLevel(consts.KLoggerLevel)
}
func main() {
r, err := etcd.NewEtcdRegistry([]string{consts.ETCDAddress})
if err != nil {
panic(err)
}
addr, err := net.ResolveTCPAddr(consts.TCP, consts.SocialServiceAddr)
if err != nil {
panic(err)
}
Init()
provider.NewOpenTelemetryProvider(
provider.WithServiceName(consts.SocialServiceName),
provider.WithExportEndpoint(consts.ExportEndpoint),
provider.WithInsecure(),
)
svr := socialservice.NewServer(new(SocialServiceImpl),
server.WithServiceAddr(addr),
server.WithRegistry(r),
server.WithLimit(&limit.Option{MaxConnections: 1000, MaxQPS: 100}),
server.WithMuxTransport(),
server.WithMiddleware(mw.CommonMiddleware),
server.WithMiddleware(mw.ServerMiddleware),
server.WithSuite(tracing.NewServerSuite()),
server.WithServerBasicInfo(&rpcinfo.EndpointBasicInfo{ServiceName: consts.SocialServiceName}),
)
err = svr.Run()
if err != nil {
klog.Fatal(err)
}
}