goease

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

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

func FloatToString(num float64) string

Float to String Conversion Example usage: floatStr := FloatToString(123.456) fmt.Println("Converted string:", floatStr)

func FormatUnixTime

func FormatUnixTime(unixTime int64, layout string) string

Format Unix Time to String Example usage: formattedTime := FormatUnixTime(1609459200, "2006-01-02 15:04:05") fmt.Println("Formatted time:", formattedTime)

func IntContains

func IntContains(slice []int, element int) bool

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

func IntToString(num int) string

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

func JoinInts(ints []int, sep string) string

Join Int Slice to String Example usage: ints := []int{1, 2, 3, 4} joined := JoinInts(ints, ", ") fmt.Println("Joined string:", joined)

func ParseCustomDate

func ParseCustomDate(dateStr, layout string) time.Time

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

func ParseISO8601Date(dateStr string) time.Time

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

func ParseRFC3339Date(dateStr string) time.Time

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

func SplitString(input, delimiter string) []string

SplitString splits a string into an array of substrings based on a delimiter.

func StringContains

func StringContains(s []string, e string) bool

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

func StringToBool(str string) (bool, error)

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

func StringToFloat(str string) (float64, error)

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

func StringToInt(str string) (int, error)

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 ToLowerCase(text string) string

func TrimSpaces

func TrimSpaces(str string) string

Trim String Spaces Example usage: trimmed := TrimSpaces(" hello world ") fmt.Println("Trimmed string:", trimmed)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL