io

package
v0.46.2-util-print-chu... Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: AGPL-3.0 Imports: 10 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy added in v0.16.1

func Copy(srcFile, dstFile string) (errToReturn error)

func CopyDirectory added in v0.16.1

func CopyDirectory(scrDir, dest string) error

CopyDirectory recursively copies a directory. From https://stackoverflow.com/questions/51779243/copy-a-folder-in-go

func CopySymLink(source, dest string) error

func CreateIfNotExists added in v0.16.1

func CreateIfNotExists(dir string, perm os.FileMode) error

func Exists added in v0.16.1

func Exists(filePath string) bool

func FileExists added in v0.14.0

func FileExists(filename string) bool

func ReadFile

func ReadFile(path string) ([]byte, error)

ReadFile reads the file from path, if not found, it will print the absolute path, instead of relative path.

func TerminateOnFullDisk added in v0.28.0

func TerminateOnFullDisk(err error) error

TerminateOnFullDisk panics if the input error is (or wraps) the system "out of disk space" error. It's a no-op for any other error, or nil.

func WriteFile added in v0.15.0

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

WriteFile writes a byte array to the file at the given path. This method will also create the directory and file as needed.

func WriteJSON added in v0.20.0

func WriteJSON(path string, data interface{}) error

WriteJSON marshals the given interface into JSON and writes it to the given path

func WriteText added in v0.16.1

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

WriteText writes a byte array to the file at the given path.

Types

type FileLock

type FileLock struct {
	// contains filtered or unexported fields
}

FileLock represents an exclusive file lock that prevents multiple processes from accessing the same resource. If another process tries to acquire the lock, it will fail and should crash.

func NewFileLock

func NewFileLock(path string) (*FileLock, error)

NewFileLock creates a new file lock at the specified path. The lock file will be created in the same directory as the path. If path is a directory, the lock file will be created inside it. If the directory doesn't exist yet, it assumes the path is intended to be a directory.

func (*FileLock) Close

func (fl *FileLock) Close() error

Close releases the file lock. Implements io.Closer.

func (*FileLock) IsLocked

func (fl *FileLock) IsLocked() bool

IsLocked returns true if this FileLock instance currently holds the lock.

func (*FileLock) Lock

func (fl *FileLock) Lock() error

Lock acquires an exclusive lock on the file. This will block until the lock can be acquired. If the lock cannot be acquired (e.g., another process holds it), it returns an error. The process should crash in this case.

func (*FileLock) Path

func (fl *FileLock) Path() string

Path returns the path to the lock file.

func (*FileLock) Unlock

func (fl *FileLock) Unlock() error

Unlock releases the file lock.

Jump to

Keyboard shortcuts

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