utils

package
v0.1.9 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendToFile

func AppendToFile(path, content string) error

AppendToFile appends content to a file

func ChangeDir

func ChangeDir(dir string) error

ChangeDir changes the current working directory

func CleanPath

func CleanPath(path string) string

CleanPath cleans a file path, resolving any relative components

func CopyFile

func CopyFile(src, dst string) error

CopyFile copies a file from src to dst

func CreateDir

func CreateDir(path string) error

CreateDir creates a directory with all parent directories

func CreateFile

func CreateFile(path, content string) error

CreateFile creates a file with the given content

func DeleteDir

func DeleteDir(path string) error

DeleteDir deletes a directory and all its contents

func DeleteFile

func DeleteFile(path string) error

DeleteFile deletes a file

func DirExists

func DirExists(path string) bool

DirExists checks if a directory exists

func EnsureDir

func EnsureDir(dir string) error

EnsureDir ensures that a directory exists, creating it if necessary

func FileExists

func FileExists(path string) bool

FileExists checks if a file exists

func GetAbsolutePath

func GetAbsolutePath(path string) (string, error)

GetAbsolutePath returns the absolute path of a file

func GetCurrentDir

func GetCurrentDir() (string, error)

GetCurrentDir returns the current working directory

func GetDirName

func GetDirName(path string) string

GetDirName returns the directory component of a path

func GetFileExt

func GetFileExt(path string) string

GetFileExt returns the file extension

func GetFileName

func GetFileName(path string) string

GetFileName returns the filename component of a path

func GetFileSize

func GetFileSize(path string) (int64, error)

GetFileSize returns the size of a file in bytes

func GetHomeDir

func GetHomeDir() (string, error)

GetHomeDir returns the user's home directory

func GetRelativePath

func GetRelativePath(base, target string) (string, error)

GetRelativePath returns the relative path from base to target

func IsEmpty

func IsEmpty(dir string) (bool, error)

IsEmpty checks if a directory is empty

func IsExecutable

func IsExecutable(path string) bool

IsExecutable checks if a file is executable

func JoinPath

func JoinPath(elements ...string) string

JoinPath joins path elements into a single path

func ListDirs

func ListDirs(dir string) ([]string, error)

ListDirs lists all directories in a directory

func ListFiles

func ListFiles(dir string) ([]string, error)

ListFiles lists all files in a directory

func MakeExecutable

func MakeExecutable(path string) error

MakeExecutable makes a file executable

func ReadFile

func ReadFile(path string) (string, error)

ReadFile reads the entire content of a file

func ReadLines

func ReadLines(path string) ([]string, error)

ReadLines reads all lines from a file

func ReplaceInFile

func ReplaceInFile(path, old, newVal string) error

ReplaceInFile replaces all occurrences of old with new in a file

func RunCommand

func RunCommand(name string, args ...string) error

RunCommand executes a shell command and returns an error if it fails

func RunCommandInDir

func RunCommandInDir(dir, name string, args ...string) error

RunCommandInDir executes a shell command in a specific directory

func RunCommandWithOutput

func RunCommandWithOutput(name string, args ...string) (string, error)

RunCommandWithOutput executes a shell command and returns its output

func SanitizeFileName

func SanitizeFileName(name string) string

SanitizeFileName sanitizes a filename by removing invalid characters

func SplitPath

func SplitPath(path string) (string, string)

SplitPath splits a path into directory and filename

func ValidateModulePath

func ValidateModulePath(path string) error

ValidateModulePath validates a Go module path

func ValidateProjectName

func ValidateProjectName(name string) error

ValidateProjectName validates a project name

func WriteLines

func WriteLines(path string, lines []string) error

WriteLines writes lines to a file

Types

This section is empty.

Jump to

Keyboard shortcuts

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