Documentation
¶
Index ¶
- Constants
- func AddToMap[K cmp.Ordered, V any, M map[K]V](m1, m2 M) M
- func After(content string, sep string) string
- func Before(content string, sep string) string
- func BoolToString(value bool) string
- func CopyCmd() string
- func DateToString(value *time.Time) string
- func DirExists(pathParts ...string) bool
- func EnsureDir(pathElem ...string) string
- func EnsureModTime(filePath string) time.Time
- func EnsureNoDir(pathElem ...string) string
- func EnsureReadDir(pathElem ...string) []os.DirEntry
- func FileExists(pathParts ...string) bool
- func FindLineInFile(filename string, predicate func(line string) bool, trimResult bool) (string, int)
- func FindLineInFileStartingWith(filename string, startsWith string, trimResult bool, cutStart bool) (string, int)
- func Float32ToString(value float32) string
- func Float64ToString(value float64) string
- func GetFirstMapValue[K cmp.Ordered, V any](m map[K]V) (value V)
- func GetOneMapValue[K cmp.Ordered, V any](m map[K]V) (value V)
- func GetSortedKeys[K cmp.Ordered, V any](m map[K]V) (keys []K)
- func GetSortedValues[K cmp.Ordered, V any](m map[K]V) (values []V)
- func GetValueFromMap(m map[string]any, key string, moreKeys ...string) any
- func IfThenElse[T any](condition bool, valueIfTrue, valueIfFalse T) T
- func InSlice[V comparable](s []V, el V) bool
- func Int64ToString(value int64) string
- func IntToString(value int) string
- func IsLinux() bool
- func IsWindows() bool
- func KebabToPascal(s string) string
- func MapFn[T, U any](input []T, transform func(T) U) []U
- func MapToString[MK cmp.Ordered, MV any](m map[MK]MV, sortedKeys bool, keyValSep, pairSep string) string
- func MoveCmd() string
- func Now() *time.Time
- func PadRight(s string, width int, with string) string
- func PanicIfErr(err error)
- func PanicMsg(str string, params ...any)
- func PanicMsgIf(cond bool, str string, params ...any)
- func PanicMsgIfErr(err error, str string, params ...any)
- func PascalToCamel(s string) string
- func PascalToKebab(s string) string
- func PascalToShort(pascalCasedString string) (result string)
- func PascalToSnake(s string) string
- func RandomString(length int) string
- func ReadFile(filename string, failIfNotExist bool) []byte
- func ReadFileFromJSON[T any, Y *T](filename string, obj Y, failIfNotExist bool) Y
- func ReadFileFromYAML[T any, Y *T](filename string, obj Y, failIfNotExist bool) Y
- func RemoveCmd() string
- func ReplaceInFile(filename string, replacements map[string]string)
- func ReplaceInFolder(folder string, extension string, replacements map[string]string)
- func ReverseMap[K comparable, V comparable](m map[K]V) map[V]K
- func SlicesEquals[T cmp.Ordered](slice1, slice2 []T, sortedAlready bool) bool
- func StringToBool(valueAsString, context string) bool
- func StringToDate(valueAsString, context string) *time.Time
- func StringToFloat32(valueAsString, context string) float32
- func StringToFloat64(valueAsString, context string) float64
- func StringToInt(valueAsString, context string) int
- func StringToInt64(valueAsString, context string) int64
- func ToAcronym(input string) string
- func ToAnySlice[T any](source []T) (target []any)
- func ToPascal(s string) string
- func WriteBytesToFile(filename string, bytes []byte)
- func WriteJsonObjToFile(filename string, obj any)
- func WriteStringToFile(filename string, content string, params ...any)
- func WriteToFile(content string, filepaths ...string)
- type EnvType
Constants ¶
const RFC3339Milli = "2006-01-02T15:04:05.000Z07:00"
custom time format, on top of the most used RFC3339
Variables ¶
This section is empty.
Functions ¶
func BoolToString ¶
BoolToString converts a boolean to a string
func DateToString ¶
DateToString converts a date to a string
func EnsureModTime ¶
Returns the given file's modification time, or panics
func EnsureNoDir ¶
EnsureNoDir removes the directory with the given path elements
func EnsureReadDir ¶
EnsureReadDir is a convenient shortcut to list a directory's files and folders
func FileExists ¶
FileExists checks if a file exists at the specified path.
func FindLineInFile ¶
func FindLineInFile(filename string, predicate func(line string) bool, trimResult bool) (string, int)
Function to scan a file given by its filename, and returning the first line verifying the given predicate, and its index, starting from 1
func FindLineInFileStartingWith ¶
func FindLineInFileStartingWith(filename string, startsWith string, trimResult bool, cutStart bool) (string, int)
Returns the line (and its index) from a file that start with a given argument; The result may be returned with the argument being cut, if cut = true
func Float32ToString ¶
Float32ToString converts a float32 to a string
func Float64ToString ¶
Float64ToString converts a float64 to a string
func GetFirstMapValue ¶
GetFirstMapValue returns the value corresponding to the first key, having sorted the keys beforehand
func GetOneMapValue ¶
GetOneMapValue randomly returns a value from the map
func GetSortedKeys ¶
GetSortedKeys returns a sorted slice of keys from a map. K must be a comparable type, which is a constraint satisfied by all types that can be map keys.
func GetSortedValues ¶
GetSortedValues returns a sorted slice of values from a map, the order of values corresponding to the order of sorted keys. K must be a comparable type, which is a constraint satisfied by all types that can be map keys.
func GetValueFromMap ¶ added in v1.0.2
GetValueFromMap returns a value from the map based on the provided path of keys. If any key in the path does not exist, it returns the zero value of V.
func IfThenElse ¶
IfThenElse returns the valueIfTrue if the condition is true, otherwise it returns the valueIfFalse
func InSlice ¶
func InSlice[V comparable](s []V, el V) bool
InSlice returns true if the slice s contains the given element el
func Int64ToString ¶
Int64ToString converts a int64 to a string
func KebabToPascal ¶
KebabToPascal converts a kebab-case string to PascalCase
func MapFn ¶
func MapFn[T, U any](input []T, transform func(T) U) []U
Generic Map function for slices
func MapToString ¶
func MapToString[MK cmp.Ordered, MV any](m map[MK]MV, sortedKeys bool, keyValSep, pairSep string) string
MapToString returns a string representation of the map, with each key-value pair formatted as "key<keyValSep>value" and pairs separated by "pairSep"
func PadRight ¶ added in v1.0.3
PadRight pads the given string with spaces on the right to reach the specified width
func PanicMsgIf ¶
PanicMsgIf panics with the given message if the condition is true
func PanicMsgIfErr ¶
PanicMsgIfErr panics with the given message if the error is not nil
func PascalToCamel ¶
PascalToCamel converts a PascalCase string to camelCase. Acronyms are title-cased: DeviceID → deviceId, URLParser → urlParser.
func PascalToKebab ¶
PascalToKebab converts a PascalCase string to kebab-case.
func PascalToShort ¶ added in v1.0.4
func PascalToSnake ¶
PascalToSnake converts a PascalCase string to snake_case.
func RandomString ¶
RandomString generates a random string of the given length
func ReadFileFromJSON ¶
ReadFileFromJSON reads the file with the given path and unmarshals the JSON object
func ReadFileFromYAML ¶
ReadFileFromYAML reads the file with the given path and unmarshals the YAML object
func ReplaceInFile ¶
ReplaceInFile performs the given replacements in the file with the given path
func ReplaceInFolder ¶
ReplaceInFolder performs the given replacements in the files within the given folder, with the given extension Example:
("src", ".go", map[string]{"foo":"bar", "toto":"titi"}) =>
replaces "boo" with "bar", and "toto" with "titi", in all the *.go files found in "./src".
func ReverseMap ¶
func ReverseMap[K comparable, V comparable](m map[K]V) map[V]K
Reverse returns a new map with keys and values swapped. Note that if the original map has duplicate values, only one of the corresponding keys will be present in the reversed map.
func SlicesEquals ¶
Tells if two slices are identical; works for primitive slices, but probably not object slices
func StringToBool ¶
StringToBool converts a string to a boolean
func StringToDate ¶
StringToDate converts a string to a date
func StringToFloat32 ¶
StringToFloat32 converts a string to a float32
func StringToFloat64 ¶
StringToFloat64 converts a string to a float64
func StringToInt ¶
StringToInt converts a string to a int
func StringToInt64 ¶
StringToInt64 converts a string to a int64
func ToAnySlice ¶
func WriteBytesToFile ¶
WriteBytesToFile writes the given bytes to the file with the given path
func WriteJsonObjToFile ¶
WriteJsonObjToFile writes the given JSON object to the file with the given path
func WriteStringToFile ¶
WriteStringToFile writes the given string to the file with the given path
func WriteToFile ¶
WriteToFile writes the given content to the file with the given path
Types ¶
type EnvType ¶
type EnvType int
EnvType represents the type of environment we're running the app in