term

package
v1.11.1 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterConnector added in v1.9.3

func RegisterConnector(c Connector)

RegisterConnector 注册一个终端连接插件。

Types

type ChainBuilder added in v1.9.3

type ChainBuilder interface {
	Build(chain GatewayChain) (Transport, error)
}

ChainBuilder 负责将一条 GatewayChain 构建为一个 Transport。 不同的实现可以支持不同的多跳策略(例如纯 SSH、多协议混合等)。

type ConnectOptions added in v1.9.3

type ConnectOptions map[string]any

ConnectOptions 为不同协议预留的扩展参数。

type Connector added in v1.9.3

type Connector interface {
	// Name 返回协议/插件名称,例如 "ssh"、"rdp"、"k8s_exec" 等。
	Name() string

	// Connect 根据多级网关链路建立到目标的连接,返回抽象的 Session
	Connect(ctx context.Context, chain GatewayChain, opts ConnectOptions) (Session, error)
}

Connector 抽象出终端连接能力,不关心具体协议实现(SSH/RDP/VNC/K8s exec 等)。

func GetConnector added in v1.9.3

func GetConnector(name string) (Connector, bool)

GetConnector 按名称获取插件实现。

type Endpoint added in v1.9.3

type Endpoint struct {
	Host       string
	Port       int
	Username   string
	Password   string
	PrivateKey string
	Passphrase string
	AuthType   string
	Sort       int
}

Endpoint 表示一个通用的远程访问端点(可以是网关,也可以是最终目标主机)。

type FileCapable added in v1.9.3

type FileCapable interface {
	NewSFTP() (*sftp.Client, error)
}

FileCapable 表示 Session 具备文件管理能力,例如 SFTP。

type GatewayChain added in v1.9.3

type GatewayChain []Endpoint

GatewayChain 代表从入口到目标主机的一条多级跳板链路。

type Session added in v1.9.3

type Session interface {
	Protocol() string
	Close() error
	Transport() Transport
}

Session 表示一次建立好的远程会话(可能是 SSH、RDP、K8s exec 等)。 具体能力通过能力接口进行扩展。

type SessionPool

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

SessionPool 提供并发安全的终端会话缓存池。

func NewSessionPool

func NewSessionPool() *SessionPool

NewSessionPool 实例化一个会话池。

func (*SessionPool) DeleteSession added in v1.11.1

func (p *SessionPool) DeleteSession(id int64)

DeleteSession 从池中注销并清除某个会话。

func (*SessionPool) GetSession

func (p *SessionPool) GetSession(id int64) (Session, error)

GetSession 从池中读取会话(并发读安全)。

func (*SessionPool) SetSession

func (p *SessionPool) SetSession(id int64, session Session)

SetSession 向池中存放或更新会话(写安全)。

type ShellCapable added in v1.9.3

type ShellCapable interface {
	NewTerminal(ws *websocket.Conn, rows, cols int) (TerminalSession, error)
}

ShellCapable 表示 Session 具备创建交互式终端的能力。

type TerminalSession added in v1.9.3

type TerminalSession interface {
	Start()
	Stop()
	Resize(rows, cols int) error
	Write(data []byte) error
	Ping() error
}

TerminalSession 抽象了一个与终端交互的会话能力,用于绑定 websocket。

type Transport added in v1.9.3

type Transport interface {
	Dial(ctx context.Context, ep Endpoint) (net.Conn, error)
}

Transport 抽象了多跳链路上的传输能力,负责根据 Endpoint 建立底层连接。 后续可以有多种实现:直连、SSH 多跳、代理隧道等。

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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