utils

package module
v0.0.0-...-7e057ed Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2024 License: GPL-3.0 Imports: 16 Imported by: 3

README

Utils

A hand-picked collection of useful and well-tested functions that I use frequently and in many projects (don't repeat yourself).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendLineToFile

func AppendLineToFile(file string, l string) error

AppendLineToFile appends the line l to file

func BuildWhitelistForStringSanitisation

func BuildWhitelistForStringSanitisation(wl []string) map[string]string

BuildWhitelistForStringSanitisation transfroms a slice of whitelisted substrings into a hashtable

func ConvertIntToStringAndAddFrontSpacing

func ConvertIntToStringAndAddFrontSpacing(i int64, l int) string

ConvertIntToStringAndAddFrontSpacing converts i into a string of a fixed length by adding spacing in the front

func ConvertStringToFloatOrZeroOnError

func ConvertStringToFloatOrZeroOnError(s string) float64

ConvertStringToFloatOrZeroOnError converts s to float64, or returns 0.0 if this fails

func ConvertStringToIntOrZeroOnError

func ConvertStringToIntOrZeroOnError(s string) int64

ConvertStringToIntOrZeroOnError tries to convert s to an int64, or returns 0 if this fails

func CreateFolder

func CreateFolder(f string) error

CreateFolder creates a the folder f

func DoesFileExist

func DoesFileExist(p string) bool

DoesFileExist returns true, if a file exists (and actually is a file)

func DoesFolderExist

func DoesFolderExist(p string) bool

DoesFolderExist returns true, if a folder exists (and actually is a folder)

func DoesStringContainsNonWhitelistedSubstrings

func DoesStringContainsNonWhitelistedSubstrings(s string, whitelist map[string]string) bool

DoesStringContainsNonWhitelistedSubstrings returns false if s contains substrings which are not in whitelist

func FirstCharacterToUppercase

func FirstCharacterToUppercase(s string) string

FirstCharacterToUppercase converts the first character of a string to uppercase

func GenerateNewSHA256Sum

func GenerateNewSHA256Sum() string

GenerateNewSHA256Sum returns a fresh SHA256Sum

func GenerateNewUUID

func GenerateNewUUID() string

GenerateNewUUID returns a fresh UUID

func GetAllFilesInFolderByExtension

func GetAllFilesInFolderByExtension(pathToFolder string, extension string) []string

GetAllFilesInFolderByExtension returns all files by extension of a given folder recursively

func GetAllStringKeysOfMap

func GetAllStringKeysOfMap(in interface{}) []string

GetAllStringKeysOfMap returns all keys of a map with string keys (sorted)

func GetCurrentYear

func GetCurrentYear() int64

GetCurrentYear returns the current year as YYYY int64

func GetPathToParrentFolderOfThisExecutable

func GetPathToParrentFolderOfThisExecutable() string

GetPathToParrentFolderOfThisExecutable returns the path to the folder where this executable is located

func GetPathToThisExecutable

func GetPathToThisExecutable() string

GetPathToThisExecutable returns the path where this executable is located

func GetSHA256SumOfString

func GetSHA256SumOfString(s string) string

GetSHA256SumOfString returns the sha256 sum of s

func GetSharedElementsOfStringSlices

func GetSharedElementsOfStringSlices(a, b []string) []string

GetSharedElementsOfStringSlices finds the elements that are in both slices

func GetSizeOfFileInBytes

func GetSizeOfFileInBytes(p string) (int64, error)

GetSizeOfFileInBytes returns the size of a file in bytes

func GetUniqueElementsOfStringSlices

func GetUniqueElementsOfStringSlices(a, b []string) []string

GetUniqueElementsOfStringSlices finds the elements that are in the first slice but not in the second slice

func IsStringInSliceOfStrings

func IsStringInSliceOfStrings(slice []string, target string) bool

IsStringInSliceOfStrings returns true, if slice contains target

func IsValidEmail

func IsValidEmail(s string) bool

IsValidEmail returns true, if s is a email address.

func IsValidURL

func IsValidURL(s string) bool

IsValidURL returns true, if s is a valid URL

func IsValidUUID

func IsValidUUID(s string) bool

IsValidUUID returns true, if s is a valid UUID

func LoadStringFromFile

func LoadStringFromFile(pathOfFile string) (string, error)

LoadStringFromFile writes a string to a file

func PrettyPrint

func PrettyPrint(in interface{})

PrettyPrint tries to print in as a pretty JSON

func RemoveDoubledStrings

func RemoveDoubledStrings(s string, target string) string

RemoveDoubledStrings removes all duplicate occurrences of target in s

func RemoveLeadingStrings

func RemoveLeadingStrings(s string, target string) string

RemoveLeadingStrings removes all leading occurrences of target in s

func RoundFloat

func RoundFloat(f float64, p uint) float64

RoundFloat rounds f to precision p

func SanitizeStringWithWhitelist

func SanitizeStringWithWhitelist(s string, whitelist map[string]string) string

SanitizeStringWithWhitelist cleans s by all substrings which do not occur in whitelist

func WriteStringToFile

func WriteStringToFile(file string, s string) error

WriteStringToFile writes a string 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