mitm

package
v0.260317.0-preview Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action int
const (
	Pass Action = iota
	Block
	Replace
	Stop // Signal to stop processing immediately
)

type ChanSource

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

ChanSource is a bidirectional channel source that supports both reading and writing. It implements InputSource and provides a Write method for injecting messages.

func NewChanSource

func NewChanSource(buffer int) *ChanSource

NewChanSource creates a new ChanSource with the given buffer size.

func (*ChanSource) C

func (s *ChanSource) C() chan<- any

C returns the underlying channel for external use.

func (*ChanSource) Close

func (s *ChanSource) Close()

Close closes the underlying channel.

func (*ChanSource) Read

func (s *ChanSource) Read(ctx context.Context) (any, error)

Read implements InputSource. It blocks until a message is available or context is done.

func (*ChanSource) Write

func (s *ChanSource) Write(msg any)

Write injects a message into the source. It's non-blocking - if the channel is full, the message is dropped.

func (*ChanSource) WriteWait

func (s *ChanSource) WriteWait(ctx context.Context, msg any) error

WriteWait injects a message into the source, waiting until context is done if full.

type ChannelSource

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

ChannelSource reads messages from a channel

func NewChannelSource

func NewChannelSource(ch <-chan any) *ChannelSource

func (*ChannelSource) Read

func (s *ChannelSource) Read(ctx context.Context) (any, error)

type CodecMode

type CodecMode int

CodecMode defines how messages are encoded/decoded

const (
	CodecJSON CodecMode = iota // JSON encoding (default)
	CodecText                  // Plain text, line-based
)

type IOContext

type IOContext struct {
	Msg any
}

type InputHandler

type InputHandler func(ctx context.Context, c *IOContext) (Action, any, error)

type InputSource

type InputSource interface {
	Read(ctx context.Context) (any, error)
}

InputSource defines where input messages come from

type OutputHandler

type OutputHandler func(ctx context.Context, c *IOContext) (*OutputResult, error)

type OutputResult

type OutputResult struct {
	Action Action
	NewMsg any

	// 额外要写入 child stdin 的消息
	InjectToChild []any
}

当 Output 触发额外输入时返回这个

type Runner

type Runner struct {

	// Codec mode for input/output
	Codec CodecMode

	InputSource  InputSource
	InputHandler InputHandler

	OutputHandler OutputHandler
	// contains filtered or unexported fields
}

func New

func New(
	cmd *exec.Cmd,
	inputHandler InputHandler,
	outputHandler OutputHandler,
) *Runner

func (*Runner) Run

func (r *Runner) Run(ctx context.Context) error

func (*Runner) SafeWrite

func (r *Runner) SafeWrite(msg any)

type StdinSource

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

StdinSource reads JSON messages from os.Stdin

func NewStdinSource

func NewStdinSource() *StdinSource

func (*StdinSource) Read

func (s *StdinSource) Read(ctx context.Context) (any, error)

Jump to

Keyboard shortcuts

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