You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.3 KiB
40 lines
1.3 KiB
package services
|
|
|
|
import (
|
|
"github.com/TremblingV5/DouTok/config/configStruct"
|
|
"github.com/TremblingV5/DouTok/pkg/middleware"
|
|
"github.com/cloudwego/kitex/client"
|
|
"github.com/cloudwego/kitex/pkg/remote/trans/gonet"
|
|
"github.com/cloudwego/kitex/pkg/retry"
|
|
"github.com/cloudwego/kitex/pkg/rpcinfo"
|
|
"github.com/kitex-contrib/obs-opentelemetry/tracing"
|
|
etcd "github.com/kitex-contrib/registry-etcd"
|
|
"runtime"
|
|
"time"
|
|
)
|
|
|
|
func InitRPCClientArgs(serviceName string, config configStruct.Etcd) []client.Option {
|
|
registry, err := etcd.NewEtcdResolver([]string{config.GetAddr()})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
options := []client.Option{
|
|
client.WithSuite(tracing.NewClientSuite()),
|
|
client.WithMiddleware(middleware.CommonMiddleware),
|
|
client.WithInstanceMW(middleware.ClientMiddleware),
|
|
client.WithRPCTimeout(30 * time.Second), // rpc timeout
|
|
client.WithConnectTimeout(30000 * time.Millisecond), // conn timeout
|
|
client.WithFailureRetry(retry.NewFailurePolicy()), // retry
|
|
client.WithResolver(registry),
|
|
client.WithClientBasicInfo(&rpcinfo.EndpointBasicInfo{ServiceName: serviceName}),
|
|
}
|
|
|
|
if runtime.GOOS == "windows" {
|
|
options = append(options, client.WithTransHandlerFactory(gonet.NewCliTransHandlerFactory()))
|
|
} else {
|
|
options = append(options, client.WithMuxConnection(1)) // mux
|
|
}
|
|
|
|
return options
|
|
}
|
|
|