client

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

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

Functions

func GetConnValue added in v0.2.0

func GetConnValue[T any](ctx context.Context, c Client, connType ConnType, serviceName string) (T, error)

GetConnValue 按连接类型创建连接并提取底层值。

func RegisterPlugins added in v0.2.0

func RegisterPlugins(r *runtime.Registry, plugins ...runtime.ClientPlugin) error

RegisterPlugins 批量注册 client plugin。

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,
	opts ...Option,
) (Client, error)

func NewDefaultClient added in v0.2.0

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

NewDefaultClient 使用内建插件和默认配置构建 Client,便于依赖注入场景直接使用。

type ConnType

type ConnType string

ConnType 连接类型枚举

const (
	GRPC ConnType = "grpc"
	HTTP ConnType = "http"
)

type Connection

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

Connection 顶层连接接口

type Option added in v0.2.0

type Option func(*options)

func WithPlugins added in v0.2.0

func WithPlugins(plugins ...runtime.ClientPlugin) Option

WithPlugins 追加外部 client plugins。

func WithRegistry added in v0.2.0

func WithRegistry(r *runtime.Registry) Option

WithRegistry 注入已有 runtime registry。

func WithoutBuiltinPlugins added in v0.2.0

func WithoutBuiltinPlugins() Option

WithoutBuiltinPlugins 关闭内建 client plugins 自动注册。

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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