io

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package io provides utilities for input and output operations.

This package contains utilities for reading from and writing to files, along with various I/O helper functions for file operations, including configuration validation utilities.

Index

Constants

This section is empty.

Variables

View Source
var ErrBasePath = errors.New("base path cannot be empty")

ErrBasePath is returned when the base path is empty.

View Source
var ErrEmptyOutputPath = errors.New("output path cannot be empty")

ErrEmptyOutputPath is returned when the output path is empty.

View Source
var ErrPathOutsideBase = errors.New("invalid path: file is outside base directory")

ErrPathOutsideBase is returned when a file path is outside the specified base directory.

Functions

func ExpandHomePath

func ExpandHomePath(path string) (string, error)

ExpandHomePath expands a path beginning with ~/ to the user's home directory.

func FindFile

func FindFile(filePath string) (string, error)

FindFile resolves a file path with directory traversal. For absolute paths, returns the path as-is. For relative paths, traverses up from the current directory to find the file. Returns the resolved absolute path if found, or the original path if not found.

func GetWriter

func GetWriter(quiet bool) io.Writer

GetWriter returns an appropriate writer based on the quiet flag. If quiet is true, returns io.Discard to silence output. If quiet is false, returns os.Stdout for normal output.

func ReadFileSafe

func ReadFileSafe(basePath, filePath string) ([]byte, error)

ReadFileSafe reads the file at path only if it is located within baseDir. It resolves absolute paths and rejects reads where the resolved path is outside baseDir (prevents path traversal and accidental file inclusion).

func TrimNonEmpty added in v1.14.0

func TrimNonEmpty(s string) (string, bool)

TrimNonEmpty returns the trimmed string and whether it's non-empty. This consolidates the common pattern of trimming and checking for emptiness.

func TryWrite

func TryWrite(content string, writer io.Writer) (string, error)

TryWrite writes content to the provided writer.

func TryWriteFile

func TryWriteFile(content string, output string, force bool) (string, error)

TryWriteFile writes content to a file path, handling force/overwrite logic. It validates that the output path doesn't contain path traversal attempts.

func WriteFileSafe

func WriteFileSafe(content, basePath, filePath string, force bool) error

WriteFileSafe writes content to a file path only if it is within the specified base directory. It prevents path traversal attacks by validating the path is within baseDir.

Types

This section is empty.

Directories

Path Synopsis
Package configmanager provides centralized configuration management using Viper.
Package configmanager provides centralized configuration management using Viper.
helpers
Package helpers provides common functionality for config managers to eliminate duplication.
Package helpers provides common functionality for config managers to eliminate duplication.
k3d
Package k3d provides configuration management for K3d v1alpha5.SimpleConfig configurations.
Package k3d provides configuration management for K3d v1alpha5.SimpleConfig configurations.
kind
Package kind provides configuration management for Kind cluster configurations.
Package kind provides configuration management for Kind cluster configurations.
ksail
Package configmanager provides configuration management for KSail v1alpha1.Cluster configurations.
Package configmanager provides configuration management for KSail v1alpha1.Cluster configurations.
testutils
Package testutils provides common test utilities for config manager testing.
Package testutils provides common test utilities for config manager testing.
Package generator provides an interface for generating files from code.
Package generator provides an interface for generating files from code.
k3d
Package k3dgenerator provides utilities for generating k3d cluster configurations.
Package k3dgenerator provides utilities for generating k3d cluster configurations.
kind
Package kindgenerator provides utilities for generating kind cluster configurations.
Package kindgenerator provides utilities for generating kind cluster configurations.
kustomization
Package kustomizationgenerator provides utilities for generating kustomization.yaml files.
Package kustomizationgenerator provides utilities for generating kustomization.yaml files.
testutils
Package testutils provides generator-specific test utilities.
Package testutils provides generator-specific test utilities.
yaml
Package yamlgenerator provides YAML generation functionality for arbitrary models.
Package yamlgenerator provides YAML generation functionality for arbitrary models.
Package marshaller provides functionality for marshaling and unmarshaling resources.
Package marshaller provides functionality for marshaling and unmarshaling resources.
yaml
Package yamlmarshaller provides functionality for marshaling and unmarshaling YAML documents.
Package yamlmarshaller provides functionality for marshaling and unmarshaling YAML documents.
Package scaffolder provides utilities for scaffolding KSail project files and configuration.
Package scaffolder provides utilities for scaffolding KSail project files and configuration.
Package validator provides interfaces for configuration file validation.
Package validator provides interfaces for configuration file validation.
k3d
Package k3d provides K3d configuration validation functionality.
Package k3d provides K3d configuration validation functionality.
kind
Package kind provides Kind configuration validation functionality.
Package kind provides Kind configuration validation functionality.
ksail
Package ksail provides validation for KSail cluster configurations.
Package ksail provides validation for KSail cluster configurations.
metadata
Package metadata provides shared metadata validation utilities used across multiple validators.
Package metadata provides shared metadata validation utilities used across multiple validators.
testutils
Package testutils provides common test utilities for validator tests to eliminate duplication.
Package testutils provides common test utilities for validator tests to eliminate duplication.

Jump to

Keyboard shortcuts

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