Documentation
¶
Index ¶
- func ConvertPascalToSnakeWithExtraKey(input map[string]interface{}, extraKeyMappings map[string]string) map[string]interface{}
- func FloatToString(num float64) string
- func FormatUnixTime(unixTime int64, layout string) string
- func IntContains(slice []int, element int) bool
- func IntToString(num int) string
- func IsSlice(v interface{}) bool
- func JoinInts(ints []int, sep string) string
- func ParseCustomDate(dateStr, layout string) time.Time
- func ParseISO8601Date(dateStr string) time.Time
- func ParseRFC3339Date(dateStr string) time.Time
- func SplitString(input, delimiter string) []string
- func StringContains(s []string, e string) bool
- func StringToBool(str string) (bool, error)
- func StringToFloat(str string) (float64, error)
- func StringToInt(str string) (int, error)
- func ToLowerCase(text string) string
- func TrimSpaces(str string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertPascalToSnakeWithExtraKey ¶
func ConvertPascalToSnakeWithExtraKey(input map[string]interface{}, extraKeyMappings map[string]string) map[string]interface{}
ConvertPascalToSnakeWithExtraKey converts keys in a map from PascalCase to snake_case. It also checks for additional key mappings defined in configs.KEY_CONVERT_MAPPING and uses those mappings if available.
Parameters:
input: A map[string]interface{} representing the input data with keys possibly in PascalCase.
Returns:
A map[string]interface{} with keys converted to snake_case. If a key is found in
configs.KEY_CONVERT_MAPPING, it will be replaced with the corresponding value. If not,
the key will be converted to snake_case.
func FloatToString ¶
Float to String Conversion Example usage: floatStr := FloatToString(123.456) fmt.Println("Converted string:", floatStr)
func FormatUnixTime ¶
Format Unix Time to String Example usage: formattedTime := FormatUnixTime(1609459200, "2006-01-02 15:04:05") fmt.Println("Formatted time:", formattedTime)
func IntContains ¶
Check if Int is in Slice Example usage: intSlice := []int{10, 20, 30, 40} intContains := IntContains(intSlice, 20) fmt.Println("Slice contains 20:", intContains)
func IntToString ¶
Int to String Conversion Example usage: str := IntToString(123) fmt.Println("Converted string:", str)
func IsSlice ¶
func IsSlice(v interface{}) bool
IsSlice checks if the given value is a slice.
This function takes an input value and checks whether it is a slice or not. It utilizes reflection to determine the kind of the value.
Parameters:
- v: interface{} - The value to be checked.
Returns:
- bool: true if the value is a slice, false otherwise.
Usage Example:
var arr []int result := IsSlice(arr) // result will be true var str string result := IsSlice(str) // result will be false
Note:
- This function is useful for checking whether a value is a slice before performing operations specific to slices.
- It uses reflection to determine the kind of the value, which may have a performance overhead.
func JoinInts ¶
Join Int Slice to String Example usage: ints := []int{1, 2, 3, 4} joined := JoinInts(ints, ", ") fmt.Println("Joined string:", joined)
func ParseCustomDate ¶
ParseCustomDate parses a date string in a custom format.
Parameters:
- dateStr: string - The date string to parse.
- layout: string - The layout to use for parsing.
Returns:
- time.Time: The parsed time if successful, otherwise a zero time.
func ParseISO8601Date ¶
ParseISO8601Date parses a date string in ISO8601 format.
Parameters:
- dateStr: string - The date string to parse.
Returns:
- time.Time: The parsed time if successful, otherwise a zero time.
func ParseRFC3339Date ¶
ParseRFC3339Date parses a date string in RFC3339 format.
Parameters:
- dateStr: string - The date string to parse.
Returns:
- time.Time: The parsed time if successful, otherwise a zero time.
func SplitString ¶
SplitString splits a string into an array of substrings based on a delimiter.
func StringContains ¶
Helper function to check if a string is in a slice of strings Check if String is in Slice Example usage: slice := []string{"apple", "banana", "cherry"} contains := StringContains(slice, "banana") fmt.Println("Slice contains 'banana':", contains)
func StringToBool ¶
Convert String to Boolean Example usage: b, err := StringToBool("true")
if err != nil {
fmt.Println("Error converting string to bool:", err)
} else {
fmt.Println("Converted boolean:", b)
}
func StringToFloat ¶
String to Float Conversion Example usage: f, err := StringToFloat("123.45")
if err != nil {
fmt.Println("Error converting string to float:", err)
} else {
fmt.Println("Converted float:", f)
}
func StringToInt ¶
String to Int Conversion Example usage: num, err := StringToInt("123")
if err != nil {
fmt.Println("Error converting string to int:", err)
} else {
fmt.Println("Converted number:", num)
}
func ToLowerCase ¶
func TrimSpaces ¶
Trim String Spaces Example usage: trimmed := TrimSpaces(" hello world ") fmt.Println("Trimmed string:", trimmed)
Types ¶
This section is empty.