streamhelpers

package
v0.0.0-...-080cee2 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// GracePeriodTimeDefault specifies the grace period, defaults to 10 seconds
	GracePeriodTimeDefault = 10 * time.Second

	// FileWriteBufferDefaultSize default write buffer size for files: 64 KiB
	FileWriteBufferDefaultSize = 65536
)

Variables

This section is empty.

Functions

func CloseIfCloseable

func CloseIfCloseable(c interface{}) error

func NewTerminatedEarlyError

func NewTerminatedEarlyError(err error) error

func RemoveFromSlice

func RemoveFromSlice[T comparable](l []T, item T) []T

Types

type CaptureFile

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

func NewCaptureFile

func NewCaptureFile(path string) *CaptureFile

func (*CaptureFile) WithFlags

func (f *CaptureFile) WithFlags(flags int) *CaptureFile

func (*CaptureFile) WithPermissions

func (f *CaptureFile) WithPermissions(file fs.FileMode, dir fs.FileMode) *CaptureFile

type CaptureFiles

type CaptureFiles struct {
	StdOUT *CaptureFile
	StdERR *CaptureFile
}

type CaptureStreams

type CaptureStreams struct {
	StdOUT io.Writer
	StdERR io.Writer
}

type CloseFunc

type CloseFunc func(err *error) error
var EmptyCloseFunc CloseFunc = func(err *error) error { return nil }

type CloseFuncPointers

type CloseFuncPointers []CloseFuncPtr

type CloseFuncPtr

type CloseFuncPtr *CloseFunc

type ConcurrentBufioWriter

type ConcurrentBufioWriter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*ConcurrentBufioWriter) Flush

func (w *ConcurrentBufioWriter) Flush()

func (*ConcurrentBufioWriter) Write

func (w *ConcurrentBufioWriter) Write(b []byte) (int, error)

func (*ConcurrentBufioWriter) WriteString

func (w *ConcurrentBufioWriter) WriteString(s string) (int, error)

type DynamicMultiWriter

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

func NewDynamicMultiWriter

func NewDynamicMultiWriter(writers ...io.Writer) *DynamicMultiWriter

NewDynamicMultiWriter Creates a dynamic multiwriter, that is able to append and remove elements on the fly Implementation is close/identical to io.MultiWriter

func (*DynamicMultiWriter) Append

func (t *DynamicMultiWriter) Append(writers ...io.Writer)

func (*DynamicMultiWriter) Remove

func (t *DynamicMultiWriter) Remove(writer io.Writer) bool

Remove Taken and modified from the original multi.go source for io.MultiReader

func (*DynamicMultiWriter) RequestAppend

func (t *DynamicMultiWriter) RequestAppend(writer io.Writer, timeout time.Duration) bool

RequestAppend This code tries to append a Writer to the running code, it will return false if the request timed out

func (*DynamicMultiWriter) Reset

func (t *DynamicMultiWriter) Reset()

func (*DynamicMultiWriter) Size

func (t *DynamicMultiWriter) Size() int

func (*DynamicMultiWriter) Write

func (t *DynamicMultiWriter) Write(p []byte) (n int, err error)

func (*DynamicMultiWriter) WriteString

func (t *DynamicMultiWriter) WriteString(s string) (n int, err error)

type OutputType

type OutputType byte
const (
	StdoutOut OutputType = iota
	StderrOut
)

type ProcessNotStartedError

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

func (*ProcessNotStartedError) Error

func (e *ProcessNotStartedError) Error() string

func (*ProcessNotStartedError) Is

func (e *ProcessNotStartedError) Is(err error) bool

type ProcessStuckError

type ProcessStuckError struct {
	PID int
}

func (*ProcessStuckError) Error

func (e *ProcessStuckError) Error() string

func (*ProcessStuckError) Is

func (e *ProcessStuckError) Is(err error) bool

type StdReader

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

func NewSTDReader

func NewSTDReader(cmd *exec.Cmd, ctx context.Context) *StdReader

NewSTDReader creates a new capture settings struct You can specify both files and streams or only one.

func (*StdReader) AlwaysKeepFiles

func (r *StdReader) AlwaysKeepFiles(val bool) *StdReader

AlwaysKeepFiles if set to true files will be always kept, even if the process terminates early or without output

func (*StdReader) AttachStream

func (r *StdReader) AttachStream(outputType OutputType, writer io.Writer, timeout time.Duration) bool

AttachStream Attach an arbitary writer to the given outputType, if you want to remove it use DetachStream(writer) to do so. Make sure to perform all closing operations yourself! Warning: Attaching a stream dynamically might fail in the case of a blocking Write taking longer than expected!

func (*StdReader) DetachStream

func (r *StdReader) DetachStream(writer io.Writer) bool

DetachStream detaches an active writer

func (*StdReader) GracefulTermination

func (r *StdReader) GracefulTermination(cmd *exec.Cmd) error

GracefulTermination gracefully terminates a process by sending SIGTERM first and then killing it Nothing in here needs a mutex, because we prevent changes once invoked is set to true

func (*StdReader) Run

func (r *StdReader) Run() error

Run Sync

func (*StdReader) SetFileWriteBufferSize

func (r *StdReader) SetFileWriteBufferSize(size int) *StdReader

SetFileWriteBufferSize sets the write buffer size for the files specified

func (*StdReader) SetGracePeriod

func (r *StdReader) SetGracePeriod(period time.Duration) *StdReader

SetGracePeriod sets the amount of time that has to pass before the process is killed if it did not respond to the termination signal.

func (*StdReader) SetTerminateMainOnly

func (r *StdReader) SetTerminateMainOnly() *StdReader

SetTerminateMainOnly Only request the main pid of the process to terminate This is dangerous and might leave processes behind, only use when you know what you are doing

func (*StdReader) SetTerminationSignal

func (r *StdReader) SetTerminationSignal(sig syscall.Signal) *StdReader

SetTerminationSignal use a custom graceful termination signal, some processes might need it to exit cleanly

func (*StdReader) Start

func (r *StdReader) Start()

Start starts the async capture

func (*StdReader) Wait

func (r *StdReader) Wait() chan error

Wait Might block forever if run was not called

func (*StdReader) WithFiles

func (r *StdReader) WithFiles(files CaptureFiles) error

WithFiles Add output files

func (*StdReader) WithStreams

func (r *StdReader) WithStreams(streams CaptureStreams) *StdReader

WithStreams Add streams that are always part of the systemthat are automatically closed by us

type TerminatedEarlyError

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

func (*TerminatedEarlyError) Error

func (e *TerminatedEarlyError) Error() string

func (*TerminatedEarlyError) Is

func (e *TerminatedEarlyError) Is(err error) bool

Jump to

Keyboard shortcuts

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