Documentation ¶
Overview ¶
Package extensions provides a set of functions to work with files, directories, and converting data types
Index ¶
- Constants
- func Between(value string, a string, b string) string
- func BigEndianUInt16(value uint16) (value1 byte, value2 byte)
- func BigEndianUInt32(value uint32) (value1 byte, value2 byte, value3 byte, value4 byte)
- func BoolToString(val bool) string
- func CopyFile(source string, dest string) (err error)
- func CopyFolder(source string, dest string) (err error)
- func DWordToInt(data []byte) (num int32)
- func DirSize(path string) (int64, error)
- func DirSizeWithSearch(path string, fileSearch string) (int64, error)
- func DoesFileExist(path string) bool
- func DoesFileNotExist(path string) bool
- func ExtractArgsWithinBrackets(str string) (res []string)
- func FloatToString(input_num float64, precision int) string
- func GenPackageImport(name string, imports []string) string
- func GetAllDirWithExclude(path string, except string) ([]fs.FileInfo, error)
- func GetAllDirs(path string) (files []os.FileInfo, err error)
- func GetAllFiles(path string) (files []os.FileInfo, err error)
- func GetAllFilesDeepWithSearch(path string, fileSearch string) ([]fs.FileInfo, error)
- func GetAllFilesRecursively(fileDir string) (files []string, err error)
- func GetAllFilesRecursivelyByExtension(fileDir string, fileExtensionFilter []string) (files []string, err error)
- func GetAllFilesSortedBy(path string, fileSearch string) (files []os.FileInfo, err error)
- func GetAllFilesWithSearch(path string, fileSearch string) ([]fs.FileInfo, error)
- func GetAllFolders(path string) (files []os.FileInfo, err error)
- func GetAllFoldersWithSearch(path string, fileSearch string) ([]fs.FileInfo, error)
- func GetDecimalAndStringFromHex(twoDigitHexCode string) (decimalValue int, asciiString string, err error)
- func GetFileSize(path string) (size int64, err error)
- func GetUserAgentName(req *http.Request) (name string)
- func Gzipfunc(source string, target string) (err error)
- func HexToInt(hexStr string) int
- func Int32ToDWORD(val int32) (value []byte)
- func Int32ToInt(val int32) (ret int)
- func Int32ToString(val int32) string
- func Int64ToInt32(val int64) (ret int)
- func Int64ToString(val int64) string
- func IntToBool(val int) bool
- func IntToString(val int) string
- func InvokeMethodOnAllFilesRecursively(fileDir string, function func(*os.File) error) (files []string, fileErrors map[string]error, err error)
- func InvokeMethodOnAllFilesRecursivelyByExtension(fileDir string, fileExtensionFilter []string, function func(*os.File) error) (files []string, fileErrors map[string]error, err error)
- func IpAddressToUint32(ip string) (value uint32)
- func IsPrintable(s string) bool
- func LeftPad(s string, padStr string, pLen int) string
- func LeftPad2Len(s string, padStr string, overallLen int) string
- func MD5(path string) (string, error)
- func MakeFirstLowerCase(s string) string
- func MkDir(path string) error
- func MkDirRWAll(path string) error
- func NewUUID() (string, error)
- func ParseAndWriteFile(path string, v interface{}, perm os.FileMode) (err error)
- func PrintKiloBytes(bytes int64) string
- func PrintMegaBytes(bytes int64) string
- func PrintZettaBytes(bytes int64) string
- func Random(min, max int) int
- func RandomString(strlen int) string
- func ReadFile(path string) ([]byte, error)
- func ReadFileAndParse(path string, v interface{}) (err error)
- func RemoveDirectory(dir string) error
- func RemoveDirectoryShell(dir string) (err error)
- func RightPad(s string, padStr string, pLen int) string
- func RightPad2Len(s string, padStr string, overallLen int) string
- func Round(x, unit float64) float64
- func StringToBool(val string) bool
- func StringToFloat(val string, precision int) (r float64)
- func StringToInt(val string) int
- func StringToUInt16(val string) uint16
- func StringToUInt64(val string) uint64
- func StringToUInt8(val string) uint8
- func SyncMapAny(x *sync.Map) (ok bool)
- func SyncMapLength(x *sync.Map) (length int)
- func Tar(source string, target string) error
- func Title(str string) string
- func TrimSuffix(s, suffix string) string
- func UnGzipfunc(source, target string) error
- func UnTar(tarball, target string) error
- func Write(value string, path string) error
- func WriteAndGoFmt(value string, path string, quiet bool, perm os.FileMode) error
- func WriteAndGoFormat(value string, path string) error
- func WriteToFile(value string, path string, perm os.FileMode) error
- type ByOldestFile
- type FilePath
- type Version
Constants ¶
const ( UNIX_READ = 04 UNIX_WRITE = 02 UNIX_EX = 01 UNIX_USER_SHIFT = 6 UNIX_GROUP_SHIFT = 3 UNIX_OTH_SHIFT = 0 UNIX_USER_R = UNIX_READ << UNIX_USER_SHIFT UNIX_USER_W = UNIX_WRITE << UNIX_USER_SHIFT UNIX_USER_X = UNIX_EX << UNIX_USER_SHIFT UNIX_USER_RW = UNIX_USER_R | UNIX_USER_W UNIX_USER_RWX = UNIX_USER_RW | UNIX_USER_X UNIX_GROUP_R = UNIX_READ << UNIX_GROUP_SHIFT UNIX_GROUP_W = UNIX_WRITE << UNIX_GROUP_SHIFT UNIX_GROUP_X = UNIX_EX << UNIX_GROUP_SHIFT UNIX_GROUP_RW = UNIX_GROUP_R | UNIX_GROUP_W UNIX_GROUP_RWX = UNIX_GROUP_RW | UNIX_GROUP_X UNIX_OTH_R = UNIX_READ << UNIX_OTH_SHIFT UNIX_OTH_W = UNIX_WRITE << UNIX_OTH_SHIFT UNIX_OTH_X = UNIX_EX << UNIX_OTH_SHIFT UNIX_OTH_RW = UNIX_OTH_R | UNIX_OTH_W UNIX_OTH_RWX = UNIX_OTH_RW | UNIX_OTH_X UNIX_ALL_R = UNIX_USER_R | UNIX_GROUP_R | UNIX_OTH_R UNIX_ALL_W = UNIX_USER_W | UNIX_GROUP_W | UNIX_OTH_W UNIX_ALL_X = UNIX_USER_X | UNIX_GROUP_X | UNIX_OTH_X UNIX_ALL_RW = UNIX_ALL_R | UNIX_ALL_W UNIX_ALL_RWX = UNIX_ALL_RW | UNIX_GROUP_X UNIX_COMMON_FILE = (UNIX_USER_RW | UNIX_ALL_R) UNIX_COMMON_DIR = os.ModeDir | (UNIX_USER_RWX | UNIX_ALL_R) UNIX_DIR_RWALL = os.ModeDir | (UNIX_USER_RWX | UNIX_ALL_RW) )
These constants are to be used when you are passing an os.FileMode uint32 because it's easier to compose exactly what you want and gives you common directory that needs execute.
Variables ¶
This section is empty.
Functions ¶
func BigEndianUInt16 ¶
BigEndianUInt16 will convert a uint16 to 2 bytes
func BigEndianUInt32 ¶
BigEndianUInt32 will convert a uint32 to 4 bytes
func CopyFolder ¶
CopyFolder copies a folder to another folder
func DirSizeWithSearch ¶
DirSizeWithSearch returns the size of a directory with a search string
func DoesFileNotExist ¶
DoesFileNotExist checks if a file does not exist
func ExtractArgsWithinBrackets ¶
ExtractArgsWithinBrackets extracts the arguments within brackets
func FloatToString ¶
FloatToString converts a float to a string
func GenPackageImport ¶
GenPackageImport a utility for initilizing a go package file
func GetAllDirWithExclude ¶
GetAllDirWithExclude returns all directories in a directory excluding the exclude string
func GetAllDirs ¶
GetAllDirs returns all directories in a directory
func GetAllFiles ¶
GetAllFiles returns all files in a directory
func GetAllFilesDeepWithSearch ¶
GetAllFilesDeepWithSearch recursively returns all files in a directory with a search string
func GetAllFilesRecursively ¶
GetAllFilesRecursively recurses a directory and returns the path and file names of all the files.
func GetAllFilesRecursivelyByExtension ¶
func GetAllFilesRecursivelyByExtension(fileDir string, fileExtensionFilter []string) (files []string, err error)
GetAllFilesRecursivelyByExtension recurses a directory and returns the path and file names of all the files. Pass []string of fileExtensions as the second parameter (no need for period and cannot have multiple extensions like tar.gz)
func GetAllFilesSortedBy ¶
GetAllFilesSortedBy returns all files in a directory sorted
func GetAllFilesWithSearch ¶
GetAllFilesWithSearch returns all files in a directory with a search string
func GetAllFolders ¶
GetAllFolders returns all folders in a directory
func GetAllFoldersWithSearch ¶
GetAllFoldersWithSearch returns all folders in a directory with a search string
func GetDecimalAndStringFromHex ¶
func GetDecimalAndStringFromHex(twoDigitHexCode string) (decimalValue int, asciiString string, err error)
GetDecimalAndStringFromHex takes a hex string and returns the decimal value and the string value.
func GetFileSize ¶
func GetUserAgentName ¶
GetUserAgentName will return the name of the user agent.
func Int32ToDWORD ¶
Int32ToDWORD converts an int32 to DWORD byte array.
func Int32ToInt ¶
Int32ToInt converts a 32 bit integer to a 32 bit integer
func Int32ToString ¶
Int32ToString converts a 32 bit integer to a string
func Int64ToInt32 ¶
Int64ToInt32 converts a 64 bit integer to a 32 bit integer
func Int64ToString ¶
Int64ToString converts a 64 bit integer to a string
func InvokeMethodOnAllFilesRecursively ¶
func InvokeMethodOnAllFilesRecursively(fileDir string, function func(*os.File) error) (files []string, fileErrors map[string]error, err error)
InvokeMethodOnAllFilesRecursively recurses a directory and returns the path and file names of all the files. The second parameter is a callback functon which will be called in go routines for each file where you will read the os.File and do something with it
func InvokeMethodOnAllFilesRecursivelyByExtension ¶
func InvokeMethodOnAllFilesRecursivelyByExtension(fileDir string, fileExtensionFilter []string, function func(*os.File) error) (files []string, fileErrors map[string]error, err error)
InvokeMethodOnAllFilesRecursivelyByExtension recurses a directory and returns the path and file names of all the files. Pass []string of fileExtensions as the second parameter (no need for period and cannot have multiple extensions like tar.gz). The third parameter is a callback functon which will be called in go routines for each file where you will read the os.File and do something with it
func IpAddressToUint32 ¶
IpAddressToUint32 will convert a string ip address to UInt32
func IsPrintable ¶
IsPrintable checks if a string is printable and returns true or false. If it is an emoji, it returns true even if non printables are also in the string
func LeftPad2Len ¶
LeftPad2Len functions are generally assumed to be padded with short sequences of strings
func MakeFirstLowerCase ¶
MakeFirstLowerCase makes the first letter of a string lowercase
func MkDirRWAll ¶
MkDirRWAll creates a directory with 0777 permissions
func ParseAndWriteFile ¶
ParseAndWriteFile parses a file and writes it with json.Marshal
func PrintKiloBytes ¶
PrintKiloBytes prints a number of bytes in kilobytes as a string
func PrintMegaBytes ¶
PrintMegaBytes prints a number of bytes in megabytes as a human readable string
func PrintZettaBytes ¶
PrintZettaBytes prints a number of bytes in zettabytes as a human readable string
func RandomString ¶
RandomString returns a random string of length
func ReadFileAndParse ¶
ReadFileAndParse reads a file and parses it with json.Unmarshal
func RemoveDirectoryShell ¶
RemoveDirectoryShell removes a directory using the shell
func RightPad2Len ¶
RightPad2Len functions are generally assumed to be padded with short sequences of strings
* in many cases with a single character sequence * * so we assume we can build the string out as if the char seq is 1 char and then * just substr the string if it is longer than needed * * this means we are wasting some cpu and memory work * but this always get us to want we want it to be * * in short not optimized to for massive string work * * If the overallLen is shorter than the original string length * the string will be shortened to this length (substr) *
func StringToFloat ¶
StringToFloat converts a string to a float
func StringToUInt16 ¶
StringToUInt16 converts a string to an uin16
func StringToUInt64 ¶
StringToUInt64 converts a string to an uin64
func StringToUInt8 ¶
StringToUInt8 converts a string to an uint8
func SyncMapAny ¶
SyncMapAny will return true if there are any items in the sync.Map
func SyncMapLength ¶
SyncMapLength will return true the length of items in the sync.Map
func Tar ¶
Tar takes a source and variable writers and walks 'source' writing each file found to the tar writer; the purpose for accepting multiple writers is to allow for multiple outputs (for example a file, or md5 hash)
func TrimSuffix ¶
TrimSuffix removes a suffix from a string.
func WriteAndGoFmt ¶
WriteAndGoFmt writes a file and formats it with go
func WriteAndGoFormat ¶
WriteAndGoFormat writes a file and formats it with go
Types ¶
type ByOldestFile ¶
ByOldestFile is a type for sorting files by oldest first
func (ByOldestFile) Len ¶
func (a ByOldestFile) Len() int
func (ByOldestFile) Less ¶
func (a ByOldestFile) Less(i, j int) bool
func (ByOldestFile) Swap ¶
func (a ByOldestFile) Swap(i, j int)