Documentation
¶
Overview ¶
Package fileutil provides file I/O utilities with consistent error handling and permissions.
Index ¶
- func AppendToFile(path string, content []byte) error
- func DirExists(path string) bool
- func EnsureDir(path string) error
- func FileExists(path string) bool
- func WriteConfig(path string, data []byte) error
- func WriteFile(path string, data []byte, perm os.FileMode) error
- func WriteSQL(path string, content string) error
- func WriteWithBackup(path string, content []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendToFile ¶
AppendToFile appends content to an existing file, or creates it if it doesn't exist. Adds a newline before the appended content if the file already has content.
func DirExists ¶
DirExists checks if a directory exists at the given path. Returns true if the directory exists.
func EnsureDir ¶
EnsureDir ensures a directory exists, creating it if necessary. Uses 0755 permissions for created directories.
func FileExists ¶
FileExists checks if a file exists at the given path. Returns true if the file exists and is not a directory.
func WriteConfig ¶
WriteConfig writes configuration data to a file with standard permissions (0644). Creates parent directories if they don't exist.
This is used for writing pgsquash.config.json and other config files.
Example:
err := WriteConfig("/path/to/config.json", jsonBytes)
func WriteFile ¶
WriteFile writes data to a file with the specified permissions. Creates parent directories if they don't exist.
This is the low-level function used by WriteSQL and WriteConfig.
func WriteSQL ¶
WriteSQL writes SQL content to a file with standard permissions (0644). Creates parent directories if they don't exist.
This is the standard function for writing migration SQL files, squashed output, etc.
Example:
err := WriteSQL("/path/to/migration.sql", "CREATE TABLE users (...);")
func WriteWithBackup ¶
WriteWithBackup writes content to a file after creating a backup of the existing file. If the file doesn't exist, no backup is created. Backup filename format: <original>.backup
Example:
WriteWithBackup("/path/to/file.sql", []byte("new content"))
// Creates: /path/to/file.sql.backup (if file existed)
Types ¶
This section is empty.