-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (51 loc) · 1.55 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
package main
import (
"net"
"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/kitex-contrib/obs-opentelemetry/provider"
"github.com/kitex-contrib/obs-opentelemetry/tracing"
etcd "github.com/kitex-contrib/registry-etcd"
Init "github.com/xiaohei366/TinyTiktok/cmd/user/initialize"
"github.com/xiaohei366/TinyTiktok/kitex_gen/UserServer/userservice"
mw "github.com/xiaohei366/TinyTiktok/pkg/middleware"
"github.com/xiaohei366/TinyTiktok/pkg/shared"
)
func main() {
//初始化
Init.Init()
//注册中心
r, err := etcd.NewEtcdRegistry([]string{shared.ETCDAddress})
if err != nil {
panic(err)
}
//获得开启监听的addr
addr, err := net.ResolveTCPAddr("tcp", shared.UserServiceAddr)
if err != nil {
panic(err)
}
//链路追踪相关设置
provider.NewOpenTelemetryProvider(
provider.WithServiceName(shared.UserServiceName),
provider.WithExportEndpoint(shared.ExportEndpoint),
provider.WithInsecure(),
)
//启动服务器
svr := userservice.NewServer(new(UserServiceImpl),
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: shared.UserServiceName}),
)
//启动
err = svr.Run()
if err != nil {
klog.Fatal(err)
}
}