-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
50 lines (46 loc) · 1.79 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
package main
import (
"net"
"github.com/chenmengangzhi29/douyin/dal"
relation "github.com/chenmengangzhi29/douyin/kitex_gen/relation/relationservice"
"github.com/chenmengangzhi29/douyin/pkg/bound"
"github.com/chenmengangzhi29/douyin/pkg/constants"
"github.com/chenmengangzhi29/douyin/pkg/middleware"
tracer2 "github.com/chenmengangzhi29/douyin/pkg/tracer"
"github.com/cloudwego/kitex/pkg/klog"
"github.com/cloudwego/kitex/pkg/limit"
"github.com/cloudwego/kitex/pkg/rpcinfo"
"github.com/cloudwego/kitex/server"
etcd "github.com/kitex-contrib/registry-etcd"
trace "github.com/kitex-contrib/tracer-opentracing"
)
func Init() {
tracer2.InitJaeger(constants.RelationServiceName)
dal.Init()
}
func main() {
r, err := etcd.NewEtcdRegistry([]string{constants.EtcdAddress}) // r should not be reused
if err != nil {
panic(err)
}
addr, err := net.ResolveTCPAddr("tcp", constants.RelationAddress)
if err != nil {
panic(err)
}
Init()
svr := relation.NewServer(new(RelationServiceImpl),
server.WithServerBasicInfo(&rpcinfo.EndpointBasicInfo{ServiceName: constants.RelationServiceName}), //server name
server.WithMiddleware(middleware.CommonMiddleware), // middleWare
server.WithMiddleware(middleware.ServerMiddleware),
server.WithServiceAddr(addr), //address
server.WithLimit(&limit.Option{MaxConnections: 1000, MaxQPS: 100}), //limit
server.WithMuxTransport(), //Multiplex
server.WithSuite(trace.NewDefaultServerSuite()), //tracer
server.WithBoundHandler(bound.NewCpuLimitHandler()), //BoundHandler
server.WithRegistry(r), // registry
)
err = svr.Run()
if err != nil {
klog.Fatal(err)
}
}