Documentation
¶
Overview ¶
Package util provides utility functions for operations like sorting and iterating over slices and maps
Package util provides common utility functions for the application.
Index ¶
- func GetSortedMapKeys(m map[string]string) []string
- func SortAndIterateSlice(slice []string, fn SliceProcessor)
- func SortStringSlice(slice []string)
- func ValidatePath(path string) error
- func ValidatePathWithinBase(path, basePath string) (string, error)
- func ValidateUnitName(unitName string) error
- type SliceProcessor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetSortedMapKeys ¶
GetSortedMapKeys returns a sorted slice of keys from a map for deterministic iteration.
func SortAndIterateSlice ¶
func SortAndIterateSlice(slice []string, fn SliceProcessor)
SortAndIterateSlice sorts a slice and applies a function to each item. This centralizes the common pattern of creating a copy of a slice, sorting it, and then iterating over the sorted values.
func SortStringSlice ¶ added in v0.9.0
func SortStringSlice(slice []string)
SortStringSlice sorts a string slice in-place for deterministic order.
func ValidatePath ¶ added in v0.16.1
ValidatePath validates that a path doesn't contain path traversal sequences. It uses filepath.Clean to normalize the path and checks for traversal attempts.
func ValidatePathWithinBase ¶ added in v0.16.1
ValidatePathWithinBase ensures a path stays within a base directory after cleaning. This is more secure than ValidatePath alone for critical file operations.
func ValidateUnitName ¶ added in v0.16.1
ValidateUnitName validates that a unit name is safe for use in shell commands. Unit names must follow systemd naming conventions to prevent command injection.
Types ¶
type SliceProcessor ¶
type SliceProcessor func(string)
SliceProcessor is a function that processes a string item.