Documentation
¶
Index ¶
- func Copy[Datas ~[]Data, Data any](writer Writer[Datas, Data], reader Reader[Datas, Data]) (n int64, err error)
- func CopyBuffer[Datas ~[]Data, Data any](writer Writer[Datas, Data], reader Reader[Datas, Data], buf Datas) (n int64, err error)
- type Buffer
- type BytesReadResult
- type ExecuteOptions
- type ExecuteResult
- type Option
- func WithShell(shell string) Option
- func WithShellMode(shellMode bool) Option
- func WithStderrLimit(limit int) Option
- func WithStderrStrategy(strategy TruncateStrategy) Option
- func WithStdin(stdin io.Reader) Option
- func WithStdoutLimit(limit int) Option
- func WithStdoutStrategy(strategy TruncateStrategy) Option
- func WithTimeout(timeout time.Duration) Option
- func WithWorkDir(workDir string) Option
- type ReadOption
- type ReadOptions
- type ReadResult
- type Reader
- type TruncateStrategy
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Buffer ¶
type Buffer[Datas ~[]Data, Data any] interface { Write(datas Datas) (n int, err error) Datas() Datas TotalWritten() int64 IsTruncated() bool Reset() }
func NewReadBuffer ¶
func NewReadBuffer[Datas ~[]Data, Data any](opts ReadOptions) Buffer[Datas, Data]
type BytesReadResult ¶
type BytesReadResult = ReadResult[[]byte, byte]
type ExecuteOptions ¶
type ExecuteOptions struct {
ShellMode bool
Shell string // shell 命令,默认为 "sh"
Timeout time.Duration
WorkDir string
Stdin io.Reader
StdoutLimit int // stdout 输出长度限制,0 表示不限制
StdoutStrategy TruncateStrategy // stdout 截断策略,head 或 tail
StderrLimit int // stderr 输出长度限制,0 表示不限制
StderrStrategy TruncateStrategy // stderr 截断策略,head 或 tail
}
ExecuteOptions 执行选项
type ExecuteResult ¶
type Option ¶
type Option func(*ExecuteOptions)
Option 选项函数类型
func WithStderrStrategy ¶
func WithStderrStrategy(strategy TruncateStrategy) Option
WithStderrStrategy 设置 stderr 截断策略
func WithStdoutStrategy ¶
func WithStdoutStrategy(strategy TruncateStrategy) Option
WithStdoutStrategy 设置 stdout 截断策略
type ReadOption ¶
type ReadOption func(*ReadOptions)
func WithLimit ¶
func WithLimit(limit int) ReadOption
func WithReadRest ¶
func WithReadRest(readRest bool) ReadOption
func WithStrategy ¶
func WithStrategy(strategy TruncateStrategy) ReadOption
type ReadOptions ¶
type ReadOptions struct {
Limit int // 输出长度限制,0 表示不限制
Strategy TruncateStrategy // 截断策略,head 或 tail
ReadRest bool // 是否读取剩余数据,默认不读取
}
ReadOptions 输出读取选项
type ReadResult ¶
type ReadResult[Datas ~[]Data, Data any] struct { Data Datas // 读取的数据 Total int // 总读取的字节数,包括截断后的数据 Truncated bool // 是否被截断 Error error // 读取错误 }
ReadResult 输出读取结果
func Read ¶
func Read[Datas ~[]Data, Data any](reader Reader[Datas, Data], opts ...ReadOption) ReadResult[Datas, Data]
Read 读取输出流,支持限制和截断策略
type TruncateStrategy ¶
type TruncateStrategy string
const ( TruncateHead TruncateStrategy = "head" TruncateTail TruncateStrategy = "tail" )
Click to show internal directories.
Click to hide internal directories.