connpool

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: GPL-3.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildKafkaOptions added in v1.5.0

func BuildKafkaOptions(asset *asset_entity.Asset, cfg *asset_entity.KafkaConfig, password string, sshPool *sshpool.Pool) ([]kgo.Opt, error)

func BuildTLSConfig added in v1.5.0

func BuildTLSConfig(name string, f TLSFields) (*tls.Config, error)

BuildTLSConfig 根据通用 TLS 字段构建 *tls.Config。 name 用于错误消息(例如 "Kafka"、"Redis"),方便用户定位是哪种资产的 TLS 配置出错。

func DialDatabase

func DialDatabase(ctx context.Context, asset *asset_entity.Asset, cfg *asset_entity.DatabaseConfig, password string, sshPool *sshpool.Pool) (*sql.DB, io.Closer, error)

DialDatabase 创建数据库连接(直连、SSH 隧道或 SOCKS5 代理,隧道优先) password 为已解析的明文密码,cfg.Proxy.Password 为明文,均由调用方负责解密

func DialEtcd added in v1.7.0

func DialEtcd(ctx context.Context, asset *asset_entity.Asset, cfg *asset_entity.EtcdConfig, password string, sshPool *sshpool.Pool) (*clientv3.Client, io.Closer, error)

DialEtcd 创建新的 etcd 客户端。可选走 SSH 隧道(仅对第一个 endpoint)或 SOCKS5 代理(隧道优先)。 返回的 tunnel 可为 nil(直连/代理场景)。调用方负责 client.Close() / tunnel.Close()(若非 nil)。

func DialKafka added in v1.5.0

func DialKafka(ctx context.Context, asset *asset_entity.Asset, cfg *asset_entity.KafkaConfig, password string, sshPool *sshpool.Pool) (*kgo.Client, error)

DialKafka creates a franz-go client and verifies it with Ping.

func DialMongoDB added in v1.2.0

func DialMongoDB(ctx context.Context, asset *asset_entity.Asset, cfg *asset_entity.MongoDBConfig, password string, sshPool *sshpool.Pool) (*mongo.Client, io.Closer, error)

DialMongoDB 创建 MongoDB 连接(直连、SSH 隧道或 SOCKS5 代理,隧道优先) password 为已解析的明文密码,cfg.Proxy.Password 为明文,均由调用方负责解密

func DialOSS added in v1.10.0

func DialOSS(ctx context.Context, cfg *asset_entity.OSSConfig, secret string) (*minio.Client, error)

DialOSS 新建一个 minio 客户端(HTTP 客户端,无需显式 Close)。

func DialRedis

func DialRedis(ctx context.Context, asset *asset_entity.Asset, cfg *asset_entity.RedisConfig, password string, sshPool *sshpool.Pool) (*redis.Client, io.Closer, error)

DialRedis 创建 Redis 连接(直连、SSH 隧道或 SOCKS5 代理,隧道优先) password 为已解析的明文密码,cfg.Proxy.Password 为明文,均由调用方负责解密

func GetOrDialEtcd added in v1.7.0

func GetOrDialEtcd(ctx context.Context, asset *asset_entity.Asset, cfg *asset_entity.EtcdConfig, password string, sshPool *sshpool.Pool) (*clientv3.Client, error)

GetOrDialEtcd 返回缓存中的客户端;未缓存则建立连接并缓存。

func GetOrDialOSS added in v1.10.0

func GetOrDialOSS(ctx context.Context, assetID int64, cfg *asset_entity.OSSConfig, secret string) (*minio.Client, error)

GetOrDialOSS 返回缓存的 minio 客户端,没有则新建并缓存。

func InvalidateEtcd added in v1.7.0

func InvalidateEtcd(assetID int64)

InvalidateEtcd 资产更新/删除时调用,强制清理缓存的客户端。

func InvalidateOSS added in v1.10.0

func InvalidateOSS(assetID int64)

InvalidateOSS 丢弃某资产的缓存客户端(配置更新/删除时调用)。

func KafkaConfigFingerprint added in v1.5.0

func KafkaConfigFingerprint(asset *asset_entity.Asset, cfg *asset_entity.KafkaConfig) string

func NormalizeKafkaBrokers added in v1.5.0

func NormalizeKafkaBrokers(brokers []string) []string

func ProxyChainDialContext added in v1.11.0

func ProxyChainDialContext(ctx context.Context, chain *asset_entity.ProxyChainConfig) (func(context.Context, string, string) (net.Conn, error), error)

ProxyChainDialContext resolves an asset proxy chain into a standard DialContext. A nil function means direct connection. Resolution failures must be returned to the caller instead of being downgraded to a direct connection.

func RDPDialContext added in v1.10.0

func RDPDialContext(ctx context.Context, tunnelID int64, cfg *asset_entity.RDPConfig, sshPool *sshpool.Pool) (func(ctx context.Context, network, addr string) (net.Conn, error), error)

RDPDialContext 返回 RDP 客户端的自定义拨号函数(隧道 > 代理 > 直连,与其它资产类型一致)。 直连返回 nil,调用方走库默认拨号。cfg.Proxy.Password 为明文,由调用方负责解密。 RDP 的 TLS 在协议内自行协商,这里不做 TLS 包裹;每条隧道连接独立持有 SSH 池引用, 随连接关闭自动释放,无需额外 Closer。

Types

type KafkaClientManager added in v1.5.0

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

KafkaClientManager owns bounded franz-go client reuse for UI/Wails service calls.

func NewKafkaClientManager added in v1.5.0

func NewKafkaClientManager(sshPool *sshpool.Pool) *KafkaClientManager

func (*KafkaClientManager) Acquire added in v1.5.0

func (m *KafkaClientManager) Acquire(ctx context.Context, asset *asset_entity.Asset, cfg *asset_entity.KafkaConfig, password string) (*kgo.Client, func(), error)

Acquire 借出一个缓存 client,调用方在使用结束后必须调用返回的 release。 release 内部扣减引用计数;若该 entry 已被驱逐且无人再引用则真正关闭底层 client。

func (*KafkaClientManager) Close added in v1.5.0

func (m *KafkaClientManager) Close()

func (*KafkaClientManager) CloseAsset added in v1.5.0

func (m *KafkaClientManager) CloseAsset(assetID int64)

type MongoClientCloser added in v1.2.0

type MongoClientCloser struct {
	*mongo.Client
}

MongoClientCloser wraps *mongo.Client to satisfy io.Closer.

func (*MongoClientCloser) Close added in v1.2.0

func (m *MongoClientCloser) Close() error

Close disconnects the underlying MongoDB client.

type SSHTunnel

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

SSHTunnel 管理通过 SSH 资产建立的 TCP 隧道

func NewSSHTunnel

func NewSSHTunnel(sshAssetID int64, host string, port int, pool *sshpool.Pool) *SSHTunnel

NewSSHTunnel 创建 SSH 隧道

func (*SSHTunnel) Close

func (t *SSHTunnel) Close() error

Close 是一个空操作。每条通过 Dial 创建的连接会在自身关闭时释放 SSH 池引用, 无需由 SSHTunnel 统一释放。保留此方法以满足 io.Closer 接口。

func (*SSHTunnel) Dial

func (t *SSHTunnel) Dial(ctx context.Context) (net.Conn, error)

Dial 通过 SSH 转发获得到目标地址的 net.Conn。 每条连接独立持有 SSH 池引用,连接关闭时自动释放。

type TLSFields added in v1.5.0

type TLSFields struct {
	ServerName string
	Insecure   bool
	CAFile     string
	CertFile   string
	KeyFile    string
}

TLSFields 描述构建 *tls.Config 所需的最小字段集, 由各资产类型 *Config 通过适配方法返回。

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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