Documentation
¶
Index ¶
- func CreateNewFileFromFilename(fileName string) (*os.File, error)
- func CreateUniqueFileName(targetDir, identifier, fileExtension string, attempt int) string
- func DirExistsOrCreate(dir string) error
- func FileExists(fileName string) bool
- func IsValidFilePathFormat(path string) bool
- func NewFileWatcher(logger *slog.Logger, watchDir string) (*fsnotify.Watcher, error)
- func RelocateExistingFileIfExists(fileName string) error
- func WaitForFile(logger *slog.Logger, watcher *fsnotify.Watcher, timeout time.Duration) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateNewFileFromFilename ¶
CreateNewFileFromFilename given a file name, this creates a new file on-disk for writing logs.
func CreateUniqueFileName ¶
CreateUniqueFileName creates a new unused filename at the target directory. targetDir: the directory to create the file in. identifier: the base name of the file. fileExtension: the file extension suffix. attempt: the current attempt number, to prevent infinite loops.
func DirExistsOrCreate ¶
DirExistsOrCreate checks if a directory exists, and creates it if it doesn't
func IsValidFilePathFormat ¶
IsValidFilePathFormat checks if the given string is formatted like a file path.
func NewFileWatcher ¶
NewFileWatcher creates a new fsnotify.Watcher and adds the specified directory to it.
Example usage:
watch, err := NewFileWatcher(dirName) if err != nil { log.Fatal(err) } err = WaitForFile(watch, time.Second*5) // err is set if timeout was reached if err != nil { log.Fatal(err) }
func RelocateExistingFileIfExists ¶
RelocateExistingFileIfExists checks if a file exists, and if it does, renames it to a unique name
Types ¶
This section is empty.