Documentation
¶
Index ¶
- Constants
- func ParseExitCode(payload []byte) (int, error)
- func ParseResize(payload []byte) (cols, rows uint16, err error)
- func ReadFrame(r io.Reader) (byte, []byte, error)
- func SocketPath(dataDir string) string
- func WriteError(w io.Writer, msg string) error
- func WriteExitCode(w io.Writer, code int) error
- func WriteFrame(w io.Writer, frameType byte, payload []byte) error
- func WriteResize(w io.Writer, cols, rows uint16) error
- type Client
- func (c *Client) Copy(req ProxyRequest) error
- func (c *Client) Download(req ProxyRequest, localFile io.Writer) error
- func (c *Client) Exec(req ProxyRequest, stdin io.Reader, stdout, stderr io.Writer) (int, error)
- func (c *Client) InteractiveSSH(req ProxyRequest, stdin io.Reader, stdout io.Writer, resizeCh <-chan [2]uint16) (int, error)
- func (c *Client) IsAvailable() bool
- func (c *Client) Upload(req ProxyRequest, localFile io.Reader) error
- type Pool
- type PoolDialer
- type PoolEntryInfo
- type ProxyRequest
- type ProxyResponse
- type Server
Constants ¶
View Source
const ( FrameStdout byte = 0x01 // 远程 stdout (S→C) FrameStderr byte = 0x02 // 远程 stderr (S→C) FrameStdin byte = 0x03 // 输入到远程 stdin (C→S) FrameExitCode byte = 0x04 // 退出码 4 bytes int32 BE (S→C) FrameResize byte = 0x05 // 终端大小 4 bytes: uint16 cols + uint16 rows (C→S) FrameError byte = 0x06 // 错误信息 UTF-8 (S→C) FrameFileData byte = 0x07 // 文件数据块 (双向) FrameFileEOF byte = 0x08 // 文件传输结束 (双向) FrameFileErr byte = 0x09 // 文件操作错误 (S→C) FrameOK byte = 0x0A // 操作成功 (S→C) // MaxFramePayload 最大帧负载大小 64KB MaxFramePayload = 64 * 1024 )
帧类型常量
Variables ¶
This section is empty.
Functions ¶
func ParseResize ¶
ParseResize 解析终端大小帧负载
func WriteFrame ¶
WriteFrame 写入一个帧到 writer 帧格式: [Length: 4 bytes uint32 BE] [Type: 1 byte] [Payload: Length-1 bytes]
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client 连接到 SSH 代理 socket 的客户端
func NewClientWithToken ¶
NewClientWithToken 创建带认证 token 的客户端
func (*Client) Download ¶
func (c *Client) Download(req ProxyRequest, localFile io.Writer) error
Download 通过代理下载文件
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool SSH 连接池
type PoolDialer ¶
type PoolDialer interface {
DialAsset(ctx context.Context, assetID int64) (*ssh.Client, []io.Closer, error)
}
PoolDialer 创建 SSH 连接的接口,由调用方实现以解耦凭据解析和跳板机逻辑
type PoolEntryInfo ¶
type PoolEntryInfo struct {
AssetID int64 `json:"asset_id"`
RefCount int `json:"ref_count"`
LastUsed int64 `json:"last_used"` // Unix timestamp
}
PoolEntryInfo 连接池条目信息(用于 UI 展示)
type ProxyRequest ¶
type ProxyRequest struct {
Token string `json:"token,omitempty"` // 认证 token
Op string `json:"op"` // "exec" | "upload" | "download" | "copy"
AssetID int64 `json:"asset_id"`
Command string `json:"command,omitempty"`
Cols int `json:"cols,omitempty"`
Rows int `json:"rows,omitempty"`
PTY bool `json:"pty,omitempty"`
SrcAssetID int64 `json:"src_asset_id,omitempty"` // copy: 源资产
SrcPath string `json:"src_path,omitempty"`
DstPath string `json:"dst_path,omitempty"`
}
ProxyRequest 代理请求(JSON 握手消息)
type ProxyResponse ¶
ProxyResponse 代理响应(JSON 握手响应)
Click to show internal directories.
Click to hide internal directories.