-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_rpc_payment_station.go
54 lines (49 loc) · 1.66 KB
/
client_rpc_payment_station.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 injectors
import (
"github.com/cloudwego/kitex/client"
"github.com/cloudwego/kitex/pkg/klog"
"github.com/cloudwego/kitex/pkg/xds"
"github.com/kitex-contrib/obs-opentelemetry/tracing"
xdsmanager "github.com/kitex-contrib/xds"
"github.com/kitex-contrib/xds/xdssuite"
"github.com/weedge/craftsman/cloudwego/common/kitex_gen/payment/da/paymentservice"
"github.com/weedge/craftsman/cloudwego/common/pkg/constants"
"github.com/weedge/craftsman/cloudwego/common/pkg/metadata"
)
type PaymentStationClientOptions struct {
Endpoint string `mapstructure:"endpoint"`
EnableXDS bool `mapstructure:"enableXDS"`
XDSAddr string `mapstructure:"xdsAddr"`
HostPorts []string `mapstructure:"hostPorts"`
}
func DefaultPaymentStationClientOptions() *PaymentStationClientOptions {
return &PaymentStationClientOptions{
Endpoint: "payment.station:8002",
EnableXDS: false,
XDSAddr: "istiod.istio-system.svc:15010",
HostPorts: []string{":8002"},
}
}
func InitPaymentStationClient(opts *PaymentStationClientOptions) (paymentservice.Client, error) {
if opts.EnableXDS {
err := xdsmanager.Init(xdsmanager.WithXDSServerAddress(opts.XDSAddr))
if err != nil {
klog.Fatal(err.Error())
}
return paymentservice.NewClient(
opts.Endpoint,
client.WithSuite(tracing.NewClientSuite()),
client.WithXDSSuite(xds.ClientSuite{
RouterMiddleware: xdssuite.NewXDSRouterMiddleware(
xdssuite.WithRouterMetaExtractor(metadata.ExtractFromPropagator),
),
Resolver: xdssuite.NewXDSResolver(),
}),
)
}
return paymentservice.NewClient(
constants.StationServiceName,
client.WithHostPorts(opts.HostPorts...),
client.WithSuite(tracing.NewClientSuite()),
)
}