generated from CyanAsterisk/.github
/
profile_service.go
46 lines (43 loc) · 1.65 KB
/
profile_service.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
package initialize
import (
"fmt"
"github.com/CyanAsterisk/FreeCar/server/cmd/trip/config"
"github.com/CyanAsterisk/FreeCar/server/shared/kitex_gen/profile/profileservice"
"github.com/cloudwego/hertz/pkg/common/hlog"
"github.com/cloudwego/kitex/client"
"github.com/cloudwego/kitex/pkg/klog"
"github.com/cloudwego/kitex/pkg/loadbalance"
"github.com/cloudwego/kitex/pkg/rpcinfo"
"github.com/kitex-contrib/obs-opentelemetry/provider"
"github.com/kitex-contrib/obs-opentelemetry/tracing"
consul "github.com/kitex-contrib/registry-consul"
)
// InitProfile to init profile service
func InitProfile() {
// init resolver
r, err := consul.NewConsulResolver(fmt.Sprintf("%s:%d",
config.GlobalConsulConfig.Host,
config.GlobalConsulConfig.Port))
if err != nil {
hlog.Fatalf("new consul client failed: %s", err.Error())
}
// init OpenTelemetry
provider.NewOpenTelemetryProvider(
provider.WithServiceName(config.GlobalServerConfig.ProfileSrvInfo.Name),
provider.WithExportEndpoint(config.GlobalServerConfig.OtelInfo.EndPoint),
provider.WithInsecure(),
)
// create a new client
c, err := profileservice.NewClient(
config.GlobalServerConfig.ProfileSrvInfo.Name,
client.WithResolver(r), // service discovery
client.WithLoadBalancer(loadbalance.NewWeightedBalancer()), // load balance
client.WithMuxConnection(1), // multiplexing
client.WithSuite(tracing.NewClientSuite()),
client.WithClientBasicInfo(&rpcinfo.EndpointBasicInfo{ServiceName: config.GlobalServerConfig.ProfileSrvInfo.Name}),
)
if err != nil {
klog.Fatalf("ERROR: cannot init client: %v\n", err)
}
config.ProfileClient = c
}