clients

package
v4.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetBinaryManager

func SetBinaryManager(m interface {
	EnsureBinary(name string) (string, error)
})

SetBinaryManager 设置二进制管理器

Types

type BaseClient

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

BaseClient 基础客户端实现

func NewBaseClient

func NewBaseClient(clientType ClientType, opts ...ClientOption) *BaseClient

NewBaseClient 创建基础客户端

func (*BaseClient) HTTPProxyAddr

func (c *BaseClient) HTTPProxyAddr() string

HTTPProxyAddr 返回 HTTP 代理地址

func (*BaseClient) Logs

func (c *BaseClient) Logs() string

Logs 返回日志

func (*BaseClient) Name

func (c *BaseClient) Name() string

Name 返回客户端名称

func (*BaseClient) ProxyAddr

func (c *BaseClient) ProxyAddr() string

ProxyAddr 返回代理地址(优先使用 mixed port)

func (*BaseClient) SetConfig

func (c *BaseClient) SetConfig(configPath string)

SetConfig 设置配置文件路径

func (*BaseClient) SocksProxyAddr

func (c *BaseClient) SocksProxyAddr() string

SocksProxyAddr 返回 SOCKS 代理地址

func (*BaseClient) Status

func (c *BaseClient) Status() ClientStatus

Status 获取客户端状态

func (*BaseClient) Stop

func (c *BaseClient) Stop() error

Stop 停止客户端

func (*BaseClient) Type

func (c *BaseClient) Type() ClientType

Type 返回客户端类型

type Client

type Client interface {
	// Name 返回客户端名称
	Name() string

	// Type 返回客户端类型
	Type() ClientType

	// Start 启动客户端
	Start(ctx context.Context) error

	// Stop 停止客户端
	Stop() error

	// Restart 重启客户端
	Restart(ctx context.Context) error

	// Status 获取客户端状态
	Status() ClientStatus

	// IsHealthy 检查客户端是否健康
	IsHealthy(ctx context.Context) bool

	// ProxyAddr 返回代理地址
	ProxyAddr() string

	// HTTPProxyAddr 返回 HTTP 代理地址
	HTTPProxyAddr() string

	// SocksProxyAddr 返回 SOCKS 代理地址
	SocksProxyAddr() string

	// Logs 返回日志
	Logs() string

	// SetConfig 设置配置文件路径
	SetConfig(configPath string)
}

Client 客户端接口

type ClientOption

type ClientOption func(*BaseClient)

ClientOption 客户端选项

func WithBinary

func WithBinary(binaryPath string) ClientOption

WithBinary 设置二进制文件路径

func WithConfig

func WithConfig(configPath string) ClientOption

WithConfig 设置配置文件

func WithName

func WithName(name string) ClientOption

WithName 设置名称

func WithPorts

func WithPorts(http, socks, mixed, api int) ClientOption

WithPorts 设置端口

type ClientStatus

type ClientStatus string

ClientStatus 客户端状态

const (
	StatusStopped  ClientStatus = "stopped"
	StatusStarting ClientStatus = "starting"
	StatusRunning  ClientStatus = "running"
	StatusError    ClientStatus = "error"
)

type ClientType

type ClientType string

ClientType 客户端类型

const (
	ClientXray   ClientType = "xray"
	ClientMihomo ClientType = "mihomo"
)

type Manager

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

Manager 客户端管理器

func NewManager

func NewManager() *Manager

NewManager 创建客户端管理器

func (*Manager) Add

func (m *Manager) Add(name string, client Client) error

Add 添加客户端

func (*Manager) Get

func (m *Manager) Get(name string) (Client, error)

Get 获取客户端

func (*Manager) HealthCheck

func (m *Manager) HealthCheck(ctx context.Context) map[string]bool

HealthCheck 对所有客户端进行健康检查

func (*Manager) HealthyClients

func (m *Manager) HealthyClients(ctx context.Context) []string

HealthyClients 返回健康的客户端列表

func (*Manager) List

func (m *Manager) List() []string

List 列出所有客户端

func (*Manager) Remove

func (m *Manager) Remove(name string) error

Remove 移除客户端

func (*Manager) RestartUnhealthy

func (m *Manager) RestartUnhealthy(ctx context.Context) error

RestartUnhealthy 重启不健康的客户端

func (*Manager) StartAll

func (m *Manager) StartAll(ctx context.Context) error

StartAll 启动所有客户端

func (*Manager) Status

func (m *Manager) Status() map[string]ClientStatus

Status 获取所有客户端状态

func (*Manager) StopAll

func (m *Manager) StopAll() error

StopAll 停止所有客户端

func (*Manager) UnhealthyClients

func (m *Manager) UnhealthyClients(ctx context.Context) []string

UnhealthyClients 返回不健康的客户端列表

func (*Manager) Watch

func (m *Manager) Watch(ctx context.Context, interval time.Duration, callback func(name string, healthy bool))

Watch 监控客户端状态

type MihomoClient

type MihomoClient struct {
	*BaseClient
	// contains filtered or unexported fields
}

MihomoClient Mihomo (Clash.Meta) 客户端

func NewMihomoClient

func NewMihomoClient(opts ...ClientOption) *MihomoClient

NewMihomoClient 创建 Mihomo 客户端

func (*MihomoClient) DelayTest

func (c *MihomoClient) DelayTest(ctx context.Context, proxyName string) (int, error)

DelayTest 延迟测试 (Mihomo 特有)

func (*MihomoClient) GetProxies

func (c *MihomoClient) GetProxies(ctx context.Context) (map[string]any, error)

GetProxies 获取代理列表 (Mihomo 特有)

func (*MihomoClient) IsHealthy

func (c *MihomoClient) IsHealthy(ctx context.Context) bool

IsHealthy 检查客户端是否健康

func (*MihomoClient) Restart

func (c *MihomoClient) Restart(ctx context.Context) error

Restart 重启客户端

func (*MihomoClient) SelectProxy

func (c *MihomoClient) SelectProxy(ctx context.Context, group, proxy string) error

SelectProxy 选择代理 (Mihomo 特有)

func (*MihomoClient) Start

func (c *MihomoClient) Start(ctx context.Context) error

Start 启动 Mihomo 客户端

type XrayClient

type XrayClient struct {
	*BaseClient
}

XrayClient Xray 客户端

func NewXrayClient

func NewXrayClient(opts ...ClientOption) *XrayClient

NewXrayClient 创建 Xray 客户端

func (*XrayClient) IsHealthy

func (c *XrayClient) IsHealthy(ctx context.Context) bool

IsHealthy 检查客户端是否健康

func (*XrayClient) Restart

func (c *XrayClient) Restart(ctx context.Context) error

Restart 重启客户端

func (*XrayClient) Start

func (c *XrayClient) Start(ctx context.Context) error

Start 启动 Xray 客户端

Jump to

Keyboard shortcuts

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