util

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTimeout = 30 * time.Second

DefaultTimeout is the default timeout for command execution (30 seconds)

Variables

This section is empty.

Functions

func IsSameWeek

func IsSameWeek(date1, date2 time.Time) bool

IsSameWeek returns true if both dates are in the same week (Monday-Sunday)

func IsWeekday

func IsWeekday(date time.Time) bool

IsWeekday returns true if the date is a weekday (Monday-Friday)

Types

type CommandResult

type CommandResult struct {
	Stdout   string
	Stderr   string
	ExitCode int
	Error    error
}

CommandResult holds the result of a command execution

func ExecuteCommand

func ExecuteCommand(cfg ExecConfig) CommandResult

ExecuteCommand executes a command with timeout and captures output

func ExecuteShellCommand

func ExecuteShellCommand(cmd string, timeout time.Duration) CommandResult

ExecuteShellCommand executes a shell command string (using sh -c).

SECURITY WARNING: This function executes commands through a shell, which means the command string can contain shell metacharacters (pipes, redirects, etc.). The caller MUST ensure that the command string comes from a trusted source (e.g., configuration files with appropriate file permissions) and MUST validate any user-provided input that is substituted into the command.

Example of safe usage:

  • Command from trusted config file: ✓ Safe
  • Command with validated date substitution: ✓ Safe (if date format is validated)
  • Command with arbitrary user input: ✗ UNSAFE (command injection risk)

type ExecConfig

type ExecConfig struct {
	Command string
	Args    []string
	Timeout time.Duration
}

ExecConfig holds configuration for command execution

Jump to

Keyboard shortcuts

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