utils

package
v1.0.0-beta Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var File = Files{}

File an instance of the Files struct.

View Source
var Guard = Guards{}

Guard an instance of the Guards struct.

Functions

This section is empty.

Types

type Files

type Files struct {
}

Files struct that provides file helper functions

func (*Files) CreateDirectory

func (f *Files) CreateDirectory(directory string) error

CreateDirectory creates a directory

func (*Files) Delete

func (f *Files) Delete(path string)

Delete deletes the file at the path if exists

func (*Files) DeleteIfEmpty

func (f *Files) DeleteIfEmpty(path string)

DeleteIfEmpty deletes the file at the path if it is empty

func (*Files) Exists

func (f *Files) Exists(path string) bool

Exists check if a file exists at the provided path

func (*Files) FileOrDirectoryExists

func (f *Files) FileOrDirectoryExists(path string) (bool, error)

FileOrDirectoryExists checks if a file or directory exists

func (*Files) GetCurrentDirectory

func (f *Files) GetCurrentDirectory() string

GetCurrentDirectory returns the current directory

func (*Files) GetDirectoriesFromRoot

func (f *Files) GetDirectoriesFromRoot(root string) ([]string, error)

GetDirectoriesFromRoot returns the list of directories in a root directory, including all inner sub-directories

func (*Files) GetDirectoryName

func (f *Files) GetDirectoryName(path string) string

func (*Files) GetFileExtension

func (f *Files) GetFileExtension(extensionOrPath string) string

GetFileExtension returns the extension of the file

func (*Files) GetFileName

func (f *Files) GetFileName(path string) string

GetFileName returns the name of the file from the path

func (*Files) GetFileNameWithoutExtension

func (f *Files) GetFileNameWithoutExtension(fileName string) string

GetFileNameWithoutExtension returns the name of the file without its extension.

func (*Files) GetFullPath

func (f *Files) GetFullPath(file string) string

GetFullPath returns the full path to the file

func (*Files) GetLength

func (f *Files) GetLength(path string) int64

func (*Files) IsFileEmpty

func (f *Files) IsFileEmpty(path string) bool

IsFileEmpty checks if the file at the path is empty

func (*Files) IsText

func (f *Files) IsText(extensionOrPath string) bool

IsText determines if an extension is a text file

func (*Files) Move

func (f *Files) Move(sourcePath, destPath string)

Move moves the source file to the destination

func (*Files) ReadFile

func (f *Files) ReadFile(filePath string) []byte

ReadFile reads the content of the file as []byte

func (*Files) TryCreateFile

func (f *Files) TryCreateFile(path string, useEmptyStringForTextFiles bool) bool

TryCreateFile creates a file at the path. If useEmptyStringForTextFiles is set and the file extension is text, creates an empty file with the provided name.

func (*Files) WriteStream

func (f *Files) WriteStream(path string, stream []byte)

WriteStream writes a stream to a file

func (*Files) WriteText

func (f *Files) WriteText(filePath string, text string)

WriteText writes the provided text to the file

type Guards

type Guards struct {
}

Guards struct that provides guard helper functions

func (*Guards) AgainstBadExtension

func (g *Guards) AgainstBadExtension(value string)

AgainstBadExtension guards agaist having a "." in the provided file extension.

func (*Guards) AgainstEmpty

func (g *Guards) AgainstEmpty(value string)

AgainstEmpty guards against string being empty

func (*Guards) AgainstNullOrEmptySlice

func (g *Guards) AgainstNullOrEmptySlice(values []string)

AgainstNullOrEmptySlice guards against the slice being nil or having zero length

func (*Guards) FileExists

func (g *Guards) FileExists(path string)

FileExists checks if a file exists at the provided path

func (*Guards) GuardFiles

func (g *Guards) GuardFiles(tempFile, targetFile string)

GuardFiles checks if the files exists and the have content

Jump to

Keyboard shortcuts

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