Documentation
¶
Index ¶
- func ExtractDomain(rawURL string) string
- func Hash(input string) string
- func HashBytes(input []byte) string
- func IsValidURL(rawURL string) bool
- func MakeAbsoluteURL(baseURL, relativeURL string) string
- func NormalizeURL(rawURL string) (string, error)
- type ExecOptions
- type ExecResult
- type ExecWrapper
- func (e *ExecWrapper) CheckBinary(binary string) error
- func (e *ExecWrapper) Execute(ctx context.Context, command string, args []string, options ...*ExecOptions) (*ExecResult, error)
- func (e *ExecWrapper) ExecuteSimple(ctx context.Context, command string, args ...string) (*ExecResult, error)
- func (e *ExecWrapper) ExecuteStream(ctx context.Context, command string, args []string, options ...*ExecOptions) (*StreamingExecResult, error)
- func (e *ExecWrapper) GetProcessInfo(pid int) (*ProcessInfo, error)
- func (e *ExecWrapper) GetVersion(ctx context.Context, binary string) (string, error)
- func (e *ExecWrapper) InstallBinary(ctx context.Context, binary string, installCmd string) error
- func (e *ExecWrapper) IsProcessRunning(pid int) bool
- func (e *ExecWrapper) KillProcess(pid int) error
- func (e *ExecWrapper) SafeExecute(ctx context.Context, command string, args []string, limits ResourceLimits) (*ExecResult, error)
- func (e *ExecWrapper) SetEnv(env []string)
- func (e *ExecWrapper) SetTimeout(timeout time.Duration)
- func (e *ExecWrapper) SetWorkingDir(dir string)
- type ProcessInfo
- type ResourceLimits
- type StreamingExecResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractDomain ¶
ExtractDomain extracts the domain from a URL
func MakeAbsoluteURL ¶
MakeAbsoluteURL converts a relative URL to absolute based on base URL
func NormalizeURL ¶
NormalizeURL normalizes a URL for consistent processing
Types ¶
type ExecOptions ¶
type ExecOptions struct {
Timeout time.Duration
WorkingDir string
Env []string
Input string
IgnoreError bool
CaptureOutput bool
StreamOutput bool
OutputHandler func(line string)
MaxMemoryMB int
MaxOutputSize int64
}
ExecOptions provides options for command execution
type ExecResult ¶
type ExecResult struct {
Command string `json:"command"`
Args []string `json:"args"`
Stdout string `json:"stdout"`
Stderr string `json:"stderr"`
ExitCode int `json:"exit_code"`
Duration time.Duration `json:"duration"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Success bool `json:"success"`
Error string `json:"error,omitempty"`
PID int `json:"pid"`
MemoryUsed int64 `json:"memory_used"`
CPUUsage float64 `json:"cpu_usage"`
}
ExecResult contains the results of command execution
type ExecWrapper ¶
type ExecWrapper struct {
// contains filtered or unexported fields
}
ExecWrapper provides safe execution of external tools with logging and monitoring
func NewExecWrapper ¶
func NewExecWrapper(logger zerolog.Logger) *ExecWrapper
NewExecWrapper creates a new execution wrapper
func (*ExecWrapper) CheckBinary ¶
func (e *ExecWrapper) CheckBinary(binary string) error
CheckBinary verifies that a binary exists and is executable
func (*ExecWrapper) Execute ¶
func (e *ExecWrapper) Execute(ctx context.Context, command string, args []string, options ...*ExecOptions) (*ExecResult, error)
Execute runs a command and returns the complete result
func (*ExecWrapper) ExecuteSimple ¶
func (e *ExecWrapper) ExecuteSimple(ctx context.Context, command string, args ...string) (*ExecResult, error)
ExecuteSimple runs a command with default options
func (*ExecWrapper) ExecuteStream ¶
func (e *ExecWrapper) ExecuteStream(ctx context.Context, command string, args []string, options ...*ExecOptions) (*StreamingExecResult, error)
ExecuteStream runs a command with streaming output
func (*ExecWrapper) GetProcessInfo ¶
func (e *ExecWrapper) GetProcessInfo(pid int) (*ProcessInfo, error)
GetProcessInfo returns information about a running process
func (*ExecWrapper) GetVersion ¶
GetVersion attempts to get the version of a binary
func (*ExecWrapper) InstallBinary ¶
InstallBinary attempts to install a binary using package managers
func (*ExecWrapper) IsProcessRunning ¶
func (e *ExecWrapper) IsProcessRunning(pid int) bool
IsProcessRunning checks if a process is still running
func (*ExecWrapper) KillProcess ¶
func (e *ExecWrapper) KillProcess(pid int) error
KillProcess kills a process by PID
func (*ExecWrapper) SafeExecute ¶
func (e *ExecWrapper) SafeExecute(ctx context.Context, command string, args []string, limits ResourceLimits) (*ExecResult, error)
SafeExecute provides additional safety checks and resource limits
func (*ExecWrapper) SetEnv ¶
func (e *ExecWrapper) SetEnv(env []string)
SetEnv sets the default environment variables
func (*ExecWrapper) SetTimeout ¶
func (e *ExecWrapper) SetTimeout(timeout time.Duration)
SetTimeout sets the default execution timeout
func (*ExecWrapper) SetWorkingDir ¶
func (e *ExecWrapper) SetWorkingDir(dir string)
SetWorkingDir sets the default working directory
type ProcessInfo ¶
type ProcessInfo struct {
PID int `json:"pid"`
Running bool `json:"running"`
MemoryUsage int64 `json:"memory_usage"`
CPUUsage float64 `json:"cpu_usage"`
StartTime time.Time `json:"start_time"`
Process *os.Process `json:"-"`
}
ProcessInfo contains information about a process
type ResourceLimits ¶
type ResourceLimits struct {
Timeout time.Duration
MaxMemoryMB int
MaxCPUPercent float64
MaxProcesses int
}
ResourceLimits defines resource constraints for command execution
type StreamingExecResult ¶
type StreamingExecResult struct {
Command string
Args []string
PID int
StartTime time.Time
Stdout chan string
Stderr chan string
Done chan ExecResult
Cancel context.CancelFunc
}
StreamingExecResult provides real-time output streaming