Documentation
¶
Index ¶
- func CreateGrpcClient(ctx context.Context, discovery registry.Discovery, serviceName string, ...) (grpc.ClientConnInterface, error)
- type Connection
- type LocalServiceRegistrar
- type Option
- func WithDiscovery(discovery registry.Discovery) Option
- func WithLocalServices(registrars ...LocalServiceRegistrar) Option
- func WithMiddleware(middlewares ...middleware.Middleware) Option
- func WithStreamInterceptor(interceptors ...grpc.StreamClientInterceptor) Option
- func WithUnaryInterceptor(interceptors ...grpc.UnaryClientInterceptor) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateGrpcClient ¶ added in v0.0.2
func CreateGrpcClient(ctx context.Context, discovery registry.Discovery, serviceName string, config *configv1.Bootstrap, middlewares ...middleware.Middleware) (grpc.ClientConnInterface, error)
CreateGrpcClient 根据服务名或配置地址创建 gRPC 客户端。
Types ¶
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection 统一适配 Admin 的 gRPC 客户端连接。
func NewConnection ¶
func NewConnection(ctx context.Context, clientConfig *configv1.Client, options ...Option) (*Connection, func(), error)
NewConnection 根据客户端配置初始化 gRPC 客户端连接。 endpoint 使用普通地址时直连本地或远程服务,使用 discovery:/// 前缀时通过 WithDiscovery 注入的注册中心发现服务;客户端配置为空时创建进程内连接。
func (*Connection) ClientConn ¶
func (c *Connection) ClientConn() grpc.ClientConnInterface
ClientConn 返回底层的 gRPC 客户端连接接口。
func (*Connection) Invoke ¶
func (c *Connection) Invoke(ctx context.Context, method string, args any, reply any, options ...grpc.CallOption) error
Invoke 将一元 RPC 调用转发给当前连接。
func (*Connection) NewStream ¶
func (c *Connection) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, options ...grpc.CallOption) (grpc.ClientStream, error)
NewStream 将流式 RPC 调用转发给当前连接。
type LocalServiceRegistrar ¶
type LocalServiceRegistrar func(grpc.ServiceRegistrar)
LocalServiceRegistrar 描述向进程内 gRPC 客户端注册服务的函数。
type Option ¶
type Option func(*connectionOptions)
Option 配置客户端连接的可选依赖。
func WithDiscovery ¶
WithDiscovery 为使用 discovery:/// 地址的客户端连接注入服务发现器。
func WithLocalServices ¶
func WithLocalServices(registrars ...LocalServiceRegistrar) Option
WithLocalServices 配置进程内 gRPC 客户端需要注册的服务。
func WithMiddleware ¶ added in v0.0.2
func WithMiddleware(middlewares ...middleware.Middleware) Option
WithMiddleware 为 gRPC 客户端连接追加 Kratos 客户端中间件。
func WithStreamInterceptor ¶ added in v0.0.3
func WithStreamInterceptor(interceptors ...grpc.StreamClientInterceptor) Option
WithStreamInterceptor 为 gRPC 客户端连接追加 stream 客户端拦截器。
func WithUnaryInterceptor ¶ added in v0.0.3
func WithUnaryInterceptor(interceptors ...grpc.UnaryClientInterceptor) Option
WithUnaryInterceptor 为 gRPC 客户端连接追加 unary 客户端拦截器。
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
middleware
|
|
|
metrics
Package metrics 提供 gRPC 客户端请求指标拦截器。
|
Package metrics 提供 gRPC 客户端请求指标拦截器。 |
|
ratelimit
Package ratelimit 提供 gRPC 客户端请求限流拦截器。
|
Package ratelimit 提供 gRPC 客户端请求限流拦截器。 |
|
requestid
Package requestid 提供跨 HTTP 和 gRPC 的请求标识生成与透传中间件。
|
Package requestid 提供跨 HTTP 和 gRPC 的请求标识生成与透传中间件。 |
|
retry
Package retry 提供 gRPC 客户端一元请求重试拦截器。
|
Package retry 提供 gRPC 客户端一元请求重试拦截器。 |
Click to show internal directories.
Click to hide internal directories.