tools

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package tools provides utility functions for file operations.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyKey is returned when a key name is empty.
	ErrEmptyKey = errors.New("key name cannot be empty")
	// ErrEmptySection is returned when a section name is empty and required.
	ErrEmptySection = errors.New("section name cannot be empty")
	// ErrKeyWhitespace is returned when a key has leading/trailing whitespace.
	ErrKeyWhitespace = errors.New("key name has leading or trailing whitespace")
	// ErrKeyInvalidChar is returned when a key contains invalid characters.
	ErrKeyInvalidChar = errors.New("key name contains invalid character")
	// ErrSectionWhitespace is returned when a section has leading/trailing whitespace.
	ErrSectionWhitespace = errors.New("section name has leading or trailing whitespace")
	// ErrSectionInvalidChar is returned when a section contains invalid characters.
	ErrSectionInvalidChar = errors.New("section name contains invalid character")
)

Functions

func AtomicSave added in v0.5.0

func AtomicSave(cfg *ini.File, targetPath string) error

AtomicSave atomically saves an ini.File to the specified path. It writes to a temporary file first, then renames it to prevent corruption.

func IsFileExists

func IsFileExists(file string) bool

IsFileExists checks if a file exists and is not a directory.

func TouchFile

func TouchFile(filename string) error

TouchFile creates an empty file at the specified path.

func ValidateKey added in v0.5.0

func ValidateKey(key string) error

ValidateKey validates a key name for INI files. Returns an error if the key is empty or contains invalid characters.

func ValidateSection added in v0.5.0

func ValidateSection(section string) error

ValidateSection validates a section name for INI files. Returns an error if the section contains invalid characters. Empty section is allowed as it represents the default section.

Types

This section is empty.

Jump to

Keyboard shortcuts

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