client

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ProviderSet = wire.NewSet(
	NewClient,
)

ProviderSet 是客户端的依赖注入提供者集合

Functions

func GetGRPCConn

func GetGRPCConn(ctx context.Context, c Client, serviceName string) (gogrpc.ClientConnInterface, error)

GetGRPCConn 创建并提取指定服务的 gRPC 连接接口。

Types

type Client

type Client interface {
	// CreateConn 创建指定类型的连接
	CreateConn(ctx context.Context, connType ConnType, serviceName string) (Connection, error)
}

Client 客户端接口

func NewClient

func NewClient(
	dataCfg *conf.Data,
	traceCfg *conf.Trace,
	discovery registry.Discovery,
	l logger.Logger,
) (Client, error)

type ConnType

type ConnType string

ConnType 连接类型枚举

const (
	GRPC ConnType = "grpc"
	// 未来扩展
	WebSocket ConnType = "websocket"
	HTTP      ConnType = "http"
)

type Connection

type Connection interface {
	// Value 返回原始连接对象
	Value() any
	// Close 关闭连接
	Close() error
	// IsHealthy 检查连接健康状态
	IsHealthy() bool
	// GetType 返回连接类型
	GetType() ConnType
}

Connection 顶层连接接口

type GrpcConn

type GrpcConn struct {
	// contains filtered or unexported fields
}

GrpcConn gRPC连接实现

func NewGrpcConn

func NewGrpcConn(conn gogrpc.ClientConnInterface) *GrpcConn

NewGrpcConn 创建gRPC连接封装

func (*GrpcConn) Close

func (g *GrpcConn) Close() error

Close 减少引用计数(参考pool示例)

func (*GrpcConn) GetType

func (g *GrpcConn) GetType() ConnType

GetType 返回连接类型

func (*GrpcConn) IsHealthy

func (g *GrpcConn) IsHealthy() bool

IsHealthy 检查连接健康状态

func (*GrpcConn) Value

func (g *GrpcConn) Value() any

Value 返回原始gRPC连接

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL