terminal

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContainerInfo

type ContainerInfo struct {
	OS             string   // 操作系统类型: alpine, ubuntu, centos, debian等
	Architecture   string   // 架构: amd64, arm64等
	IsAlpine       bool     // 是否为Alpine Linux
	IsBusyBox      bool     // 是否基于BusyBox
	IsDistroless   bool     // 是否为Distroless镜像
	PackageManager string   // 包管理器: apk, apt, yum等
	ShellFeatures  []string // 容器支持的shell特性
}

ContainerInfo 容器信息结构体 包含容器类型、操作系统等信息,用于优化shell选择

type Message

type Message struct {
	Op      string `json:"op"`       // 操作类型: stdin/resize/stdout
	Data    string `json:"data"`     // 消息数据内容
	RowSize uint16 `json:"row_size"` // 终端行数(resize操作使用)
	ColSize uint16 `json:"col_size"` // 终端列数(resize操作使用)
}

WebSocket 消息协议定义:

OP      DIRECTION  USED  				DESCRIPTION
---------------------------------------------------------------------
stdin   fe->be     Data           		前端发送的键盘输入/粘贴缓冲区
resize  fe->be     RowSize, ColSize    前端发送的新终端尺寸
stdout  be->fe     Data           		后端发送的进程输出

Message WebSocket消息结构体 定义了前后端通信的消息格式

type Session

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

Session 终端会话结构体 封装了WebSocket连接和终端大小变化通道

func (*Session) Close

func (t *Session) Close() error

Close 关闭会话,清理资源

func (*Session) Next

func (t *Session) Next() *remotecommand.TerminalSize

Next 实现remotecommand.TerminalSizeQueue接口 返回下一个终端大小变化,如果通道关闭则返回nil

func (*Session) Read

func (t *Session) Read(p []byte) (int, error)

Read 实现io.Reader接口,从WebSocket客户端读取数据

func (*Session) Write

func (t *Session) Write(p []byte) (int, error)

Write 实现io.Writer接口,向WebSocket客户端发送数据

type TerminalHandler

type TerminalHandler interface {
	// HandleSession 处理WebSocket终端会话
	HandleSession(ctx context.Context, shell, namespace, podName, containerName string, conn *websocket.Conn)
}

TerminalHandler 定义终端处理接口

func NewTerminalHandler

func NewTerminalHandler(client kubernetes.Interface, config *rest.Config, logger *zap.Logger) TerminalHandler

NewTerminalHandler 创建新的终端处理器 参数:

  • client: Kubernetes客户端接口
  • config: Kubernetes REST配置
  • logger: 日志记录器

type TerminalSessionHandler

type TerminalSessionHandler interface {
	io.Reader
	io.Writer
	remotecommand.TerminalSizeQueue
}

TerminalSessionHandler 终端会话处理器接口 组合了io.Reader、io.Writer和终端大小队列接口

Jump to

Keyboard shortcuts

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