Documentation
¶
Overview ¶
Package "module" defines the global functions provided by this module. The functions fill is some gaps in the Go language and native libraries. They make it easy to perform the things that should be simple in Go but aren't for various reasons. The functions cover the following areas:
- File System
- Arrays
- Maps
- Strings
- Reflection
Index ¶
- func ArraysAreEqual[V comparable](first []V, second []V) bool
- func CopyArray[V any](array []V) []V
- func CopyMap[K comparable, V any](map_ map[K]V) map[K]V
- func Format(value any) string
- func ImplementsInterface(value any, pointer any) bool
- func IsDefined(value any) bool
- func IsUndefined(value any) bool
- func MakeAllCaps(mixedCase string) string
- func MakeDirectory(directory string)
- func MakeLowerCase(mixedCase string) string
- func MakePlural(mixedCase string) string
- func MakeSnakeCase(mixedCase string) string
- func MakeUpperCase(mixedCase string) string
- func MapsAreEqual[K comparable, V comparable](first map[K]V, second map[K]V) bool
- func PathExists(path string) bool
- func ReadFile(filename string) string
- func RemakeDirectory(directory string)
- func RemovePath(path string)
- func ReplaceAll(template string, name string, value string) string
- func WriteFile(filename string, source string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ArraysAreEqual ¶ added in v2.3.0
func ArraysAreEqual[V comparable]( first []V, second []V, ) bool
ArraysAreEqual[V comparable] determines whether or not the specified arrays have the same elements.
func CopyArray ¶ added in v2.3.0
func CopyArray[V any]( array []V, ) []V
CopyArray[V any] returns a copy of the specified array with the same size and elements as the specified array. The result is not a deep copy.
func CopyMap ¶ added in v2.4.0
func CopyMap[K comparable, V any]( map_ map[K]V, ) map[K]V
CopyMap[K comparable, V any] returns a copy of the specified map with the same size and key-value pairs as the specified map. The result is not a deep copy.
func Format ¶ added in v2.5.0
Format returns a canonical string describing any value in Go. It takes into account the nesting depth of all compound values (i.e. arrays, maps and structs) and indents each four spaces per nesting level. This function does not call the Go "Stringer" interface on any of the values even if the value supports it since this the "Stringer" interface does not take into account the nesting depth.
That said, the Go "Stringer" interface can be safely implemented using the Format function as follows:
func (v *MyClass) String() string { return uti.Format(v) }
There should be no risk of infinite recursion from Format() calling String() calling Format() calling String()...
func ImplementsInterface ¶ added in v2.13.0
ImplementsInterface checks whether or not the specified value implements the specified interface. It can be used as follows:
type MyInterface interface { DoSomething() } type MyStruct struct{} func (v *MyStruct) DoSomething() {} func main() { var myValue any = &MyStruct{} var myInterface *MyInterface if ImplementsInterface(myValue, myInterface) { var actual MyInterface = myValue.(MyInterface) fmt.Println("myValue implements MyInterface:", actual) } }
NOTE: The interface argument that gets passed into the ImplementsInterface() call must be a pointer to the interface since the argument is of type any.
func IsDefined ¶
IsDefined checks whether or not the specified value is defined in a meaningful way. Empty strings and nil pointers are considered as being undefined.
func IsUndefined ¶
IsUndefined checks whether or not the specified value is undefined. Empty strings and nil pointers are considered as being undefined.
func MakeAllCaps ¶
MakeAllCaps modifies the specified mixed case string into a corresponding all uppercase string using "_"s to separate the words found in the mixed case string.
func MakeDirectory ¶ added in v2.2.0
func MakeDirectory( directory string, )
MakeDirectory creates all directories in the specified file system directory path.
func MakeLowerCase ¶
MakeLowerCase modifies the specified mixed case string into a corresponding string starting with a lowercase letter. All other letters remain unchanged.
func MakePlural ¶
MakePlural attempts to modify the specified mixed case string to make it plural. It does not use much intelligence to attempt this but gets most cases correct.
func MakeSnakeCase ¶
MakeSnakeCase modifies the specified mixed case string into a corresponding all lowercase string using "-"s to separate the words found in the mixed case string.
func MakeUpperCase ¶
MakeUpperCase modifies the specified mixed case string into a corresponding string starting with an uppercase letter. All other letters remain unchanged.
func MapsAreEqual ¶ added in v2.4.0
func MapsAreEqual[K comparable, V comparable]( first map[K]V, second map[K]V, ) bool
MapsAreEqual[K comparable, V comparable] determines whether or not the specified maps have the same key-value pairs. This function is deterministic even though Go maps are not.
func PathExists ¶ added in v2.2.0
PathExists checks whether or not the specified file system path is defined. An empty string or a nil pointer is considered to be undefined.
func ReadFile ¶ added in v2.2.0
ReadFile returns the contents of the specified file from the file system as a string.
func RemakeDirectory ¶ added in v2.2.0
func RemakeDirectory( directory string, )
RemakeDirectory recursively removes all files and subdirectories from the specified file system directory path.
func RemovePath ¶ added in v2.2.0
func RemovePath( path string, )
RemovePath recursively removes all directories and files found in the specified file system path.
func ReplaceAll ¶
ReplaceAll replaces each instance of the specified name embedded in angle brackets (i.e. "<" and ">") with the specified value throughout the specified template string. The way the name is shown in the brackets determines what transformations are done on the value prior to the substitution as follows:
- <anyCaseName> -> value {leave value as is}
- <lowerCaseName_> -> lowerCaseValue[_] {convert value to unique ⃰lower case}
- <~lowerCaseName> -> lowerCaseValue {convert value to lower case}
- <~snake-case-name> -> snake-case-value {convert value to snake case}
- <~UpperCaseName> -> UpperCaseValue {convert value to upper case}
- <~ALL_CAPS_NAME> -> ALL_CAPS_VALUE {convert value to all caps with _'s}
⃰A trailing underscore "_" is added if the value collides with a Go keyword.
Types ¶
This section is empty.