types

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

List of all valid numeric datatypes in GoLang

Functions

func Base64Decode

func Base64Decode(str string) (string, error)

Decodes base64 string and return the decoded value

func Base64Encode

func Base64Encode(str string) string

Encodes input value into base64 encoded string

func CastInterfaceSlice

func CastInterfaceSlice[T any](slice []interface{}) ([]T, error)

CastInterfaceSlice converts a slice of interfaces to a slice of type T. It returns an error if any item cannot be converted to T.

func ConvertMapToTypedMap

func ConvertMapToTypedMap[K ~string, V any](raw interface{}) map[K]V

convertMapToTypedMap converts a map[string]V or map[string]interface{} to map[K]V

func ConvertToInterfaceSlice

func ConvertToInterfaceSlice[T any](ids []T) []interface{}

func ConvertToMapInterface

func ConvertToMapInterface(m map[string]interface{}) map[interface{}]interface{}

ConvertToMapInterface converts a map with string keys to a map with interface{} keys.

func ConvertToMapStringInterface

func ConvertToMapStringInterface(m map[interface{}]interface{}) map[string]interface{}

ConvertToMapStringInterface converts a map with interface{} keys to a map with string keys.

func CopyStructFieldsRecursive

func CopyStructFieldsRecursive(dst interface{}, src interface{})

CopyStructFieldsRecursive copies fields from one struct to another recursively.

func CreateChunks

func CreateChunks(s []interface{}, size int) ([][]interface{}, error)

Create 2 dimensional chunked array from the provided one dimensional array/list of elements, as each chunk of size n provided as `size` parameter.

Example:

Input   = [1,2,3,4,5,6]
Size    = 2
Output  = [[1,2], [3,4], [5,6]]

func ExistsInList

func ExistsInList(val interface{}, array interface{}) (bool, int)

ExistsInList checks if a given value exists within a slice and returns a boolean indicating its existence and the index at which it was found.

Parameters:

  • val: The value to search for in the slice.
  • array: The slice to search within.

Returns:

  • exists: A boolean value indicating whether 'val' exists in 'array'.
  • index: An integer representing the index where 'val' was found in 'array'. If 'val' is not found, the index is set to -1.

func GetCryptoSafeRandomString

func GetCryptoSafeRandomString(length uint8) (string, error)

GetCryptoSafeRandomString generates a random string of the specified length using the crypto/rand package. The string is URL-safe and does not contain any padding characters.

func GetFunctionName

func GetFunctionName(f interface{}) string

GetFunctionName takes a function pointer and returns its fully qualified name.

It uses reflection to get the function pointer, then uses the runtime package to retrieve the function information, and finally returns the fully qualified function name.

Parameters: - f: The function pointer.

Returns: - string: The fully qualified name of the function.

func GetRandomString

func GetRandomString(length int64) string

GetRandomString generates a random string of the specified length.

func IsASCII

func IsASCII(s string) bool

IsASCII checks if a string contains only ASCII characters.

func IsEmpty

func IsEmpty(value interface{}) bool

func IsNumber

func IsNumber(value interface{}) bool

Checks if the provided variable is a number. The number can be any of type, ie signed int, unsigned int or float.

func MaxInt64

func MaxInt64(a, b int64) int64

MaxInt64 returns the maximum of two int64 numbers.

func MaxUint8

func MaxUint8(a, b uint8) uint8

MaxUint8 returns the maximum of two uint8 numbers.

func MaxUint64

func MaxUint64(a, b uint64) uint64

MaxUint64 returns the maximum of two uint32 numbers.

func MergeMaps

func MergeMaps[T any](map1, map2 map[string]T) map[string]T

MergeMaps merges two maps of the same type into one.

func NullableString

func NullableString(value interface{}) string

NullableString converts an interface{} to a string. returning an empty string if the value is nil or not a string.

func PackNumbers

func PackNumbers(num1 int32, num2 int32) int64

func PopulateStructFromMap

func PopulateStructFromMap(dst interface{}, src map[string]interface{}) error

func StructToMap

func StructToMap(data interface{}) (map[string]interface{}, error)

func ToBool

func ToBool(value interface{}) (bool, error)

ToBool converts an interface{} value to a bool.

func ToFloat32

func ToFloat32(value interface{}) (float32, error)

ToFloat32 converts an interface{} value to float32.

func ToFloat64

func ToFloat64(value interface{}) (float64, error)

ToFloat64 converts an interface{} value to float64.

func ToInt

func ToInt(value interface{}) (int, error)

func ToInt64

func ToInt64(value interface{}) (int64, error)

ToInt64 converts an interface{} value to int64.

func ToInterfaceSlice

func ToInterfaceSlice(strings []string) []interface{}

takes string slice as an input and convert that into more generic slice of interface{}

func ToString

func ToString(arg interface{}, timeFormat ...string) string

ToString changes any type of input argument to a string

func UCFirst

func UCFirst(value string) string

Capitalize the first character of provided string

func UnmarshalCustom

func UnmarshalCustom(data []byte, out interface{}) error

Generalized Unmarshal Function

func UnpackFirstNumber

func UnpackFirstNumber(packed int64) int32

Get only the first number from the packed uint64

func UnpackNumbers

func UnpackNumbers(packed int64) (int32, int32)

Unpack both numbers from the packed uint64

func UnpackSecondNumber

func UnpackSecondNumber(packed int64) int32

Get only the second number from the packed uint64

Types

This section is empty.

Jump to

Keyboard shortcuts

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