fileutil

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package fileutil provides file I/O utilities with consistent error handling and permissions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendToFile

func AppendToFile(path string, content []byte) error

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

func DirExists(path string) bool

DirExists checks if a directory exists at the given path. Returns true if the directory exists.

func EnsureDir

func EnsureDir(path string) error

EnsureDir ensures a directory exists, creating it if necessary. Uses 0755 permissions for created directories.

func FileExists

func FileExists(path string) bool

FileExists checks if a file exists at the given path. Returns true if the file exists and is not a directory.

func WriteConfig

func WriteConfig(path string, data []byte) error

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

func WriteFile(path string, data []byte, perm os.FileMode) error

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

func WriteSQL(path string, content string) error

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

func WriteWithBackup(path string, content []byte) error

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.

Jump to

Keyboard shortcuts

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