代码拉取完成,页面将自动刷新
/*
* @Author: lwnmengjing
* @Date: 2021/6/8 5:29 下午
* @Last Modified by: lwnmengjing
* @Last Modified time: 2021/6/8 5:29 下午
*/
package grpc
import (
"context"
"fmt"
"time"
log "gitee.com/linxing_3/youye-core/logger"
"gitee.com/linxing_3/youye-core/server/grpc/interceptors/logging"
reqtags "gitee.com/linxing_3/youye-core/server/grpc/interceptors/request_tag"
middleware "github.com/grpc-ecosystem/go-grpc-middleware"
opentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing"
"google.golang.org/grpc"
)
type Service struct {
Connection *grpc.ClientConn
CallTimeout time.Duration
}
func (e *Service) Dial(
endpoint string,
callTimeout time.Duration,
unary ...grpc.UnaryClientInterceptor) (err error) {
log.Infof("configure service with endpoint: %s", endpoint)
ctx, cancel := context.WithTimeout(context.Background(), callTimeout)
defer cancel()
if len(unary) == 0 {
unary = defaultUnaryClientInterceptors()
}
e.Connection, err = grpc.DialContext(ctx,
endpoint,
grpc.WithInsecure(),
grpc.WithStreamInterceptor(middleware.ChainStreamClient(defaultStreamClientInterceptors()...)),
grpc.WithUnaryInterceptor(middleware.ChainUnaryClient(unary...)),
grpc.WithDefaultCallOptions(grpc.WaitForReady(true), grpc.MaxCallRecvMsgSize(defaultMaxMsgSize)),
)
if err != nil {
msg := fmt.Sprintf("connect gRPC service %s failed", endpoint)
log.Errorf(msg, err)
return fmt.Errorf("%w, "+msg, err)
}
return nil
}
func defaultUnaryClientInterceptors() []grpc.UnaryClientInterceptor {
return []grpc.UnaryClientInterceptor{
opentracing.UnaryClientInterceptor(),
logging.UnaryClientInterceptor(),
reqtags.UnaryClientInterceptor(),
}
}
func defaultStreamClientInterceptors() []grpc.StreamClientInterceptor {
return []grpc.StreamClientInterceptor{
opentracing.StreamClientInterceptor(),
logging.StreamClientInterceptor(),
reqtags.StreamClientInterceptor(),
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。