Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GrpcClient ¶
type GrpcClient[T any] struct { Stub T // 具体业务客户端(由 ctor 构造) // contains filtered or unexported fields }
func NewGrpcClient ¶
func NewGrpcClient[T any](ctor func(cc *grpc.ClientConn) T, opts Options) (*GrpcClient[T], error)
NewGrpcClient 通过 ctor 构造具体的 pb 客户端(例如 pb.NewDemoClient)
func (*GrpcClient[T]) Close ¶
func (c *GrpcClient[T]) Close() error
func (*GrpcClient[T]) Conn ¶
func (c *GrpcClient[T]) Conn() *grpc.ClientConn
type Options ¶
type Options struct {
// 基础拨号
Target string // 形如 "dns:///host:port" 或 "ipv4:port";本地可直接 "127.0.0.1:9090"
Endpoints []string // 可选:["10.0.0.1:9090","10.0.0.2:9090"],内部自动 round_robin
Authority string // 可选:HTTP/2 :authority
// 安全
Insecure bool // true 则明文;否则走 TLS
TLSCfg *tls.Config // 可选:自定义 TLS(可含 ServerName、RootCAs、mTLS 等)
// 调用默认值
DefaultTimeout time.Duration // 默认每次调用超时(建议 2~5s)
// 拦截器
UnaryInts []grpc.UnaryClientInterceptor
StreamInts []grpc.StreamClientInterceptor
// 低级定制
ExtraDialOptions []grpc.DialOption
// gRPC ServiceConfig JSON:可用于开启官方重试/负载均衡策略等
// 如:`{"loadBalancingPolicy":"round_robin","methodConfig":[{...retryPolicy...}]}`
ServiceConfigJSON string
}
Options 配置
Click to show internal directories.
Click to hide internal directories.