Documentation
¶
Index ¶
- Variables
- func Abs[T Number](num T) T
- func ArrayAContainsBString(a []string, b string) bool
- func Combine(msgs ...any) interface{}
- func CombineToStringWithField(msgs ...any) string
- func CombineToStringWithSeparator(sep string, msgs ...any) string
- func CombineToStringWithSpace(msgs ...any) string
- func CombineTwoMaps(a, b map[string]interface{})
- func CombineTwoMapsDistinct(bwins bool, a, b map[string]interface{})
- func ExistInArrayInt(num int, arr []int) bool
- func GetDBTag(field reflect.StructField) string
- func GetJSONOrDBTag(field reflect.StructField) string
- func GetJSONTag(field reflect.StructField) string
- func GetType(a interface{}, removeDots bool) string
- func Int(smallNumber string, abs bool) int
- func IntPlus(str string, zeroValue int) int
- func LastStringAfterDelimiter(s, d string) string
- func MapToString(d map[string]interface{}) string
- func MapToStringSlice(d map[string]interface{}) []string
- func MapToStruct[T any](dict map[string]interface{}) T
- func MapToStructSlow[T any](dict map[string]interface{}) T
- func MapToStructSlowDB[T any](dict map[string]interface{}) T
- func MapToStructSlowJSON[T any](dict map[string]interface{}) T
- func MaxMinIntArray(arr []int) (max, min, maxindex, minindex int)
- func StringContainsSplitBySpace(str, rtype, separator string) bool
- func StringSliceDebug(msgs []string) string
- func StructToMap[T any](input T) map[string]interface{}
- func StructToMapDB[T any](input T) map[string]interface{}
- func StructToMapDBWithOptions[T any](input T, opts MapOptions) map[string]interface{}
- func StructToMapJSON[T any](input T) map[string]interface{}
- func StructToMapJSONWithOptions[T any](input T, opts MapOptions) map[string]interface{}
- func StructToMapWithOptions[T any](input T, opts MapOptions) map[string]interface{}
- type Float
- type Integer
- type MapOptions
- type Number
- type Signed
- type Unsigned
Constants ¶
This section is empty.
Variables ¶
var ( THOUSAND_SEPARATOR byte = ',' DECIMAL_SEPARATOR byte = '.' )
Use var so later we can change it, it is crude for now but can do: object.THOUSAND_SEPARATOR='.' before calling any of the number methods
var (
DEBUG_KEY_SEPARATOR string = ": "
)
Functions ¶
func Abs ¶
func Abs[T Number](num T) T
Simpler generic ABS func, no need to import math. Need Number Type
func ArrayAContainsBString ¶
String Array A contains item (string) B NOTE: maybe change to generics?
func Combine ¶
func Combine(msgs ...any) interface{}
Trick to combine multiple any/interface variables into 1 interface NOTE: NOT USED
func CombineToStringWithField ¶
combined key-value (json usually) into string using marshal NOT USED
func CombineToStringWithSeparator ¶
Combine array of strings with seperator (sep)
func CombineToStringWithSpace ¶
Combined with space
func CombineTwoMaps ¶
func CombineTwoMaps(a, b map[string]interface{})
Combines map A,B into A without checking if A already have the key or not, just overwrite
func CombineTwoMapsDistinct ¶
If bwins is set means b will overwrite a for the same key
func ExistInArrayInt ¶
Return true if num exists in arr
func GetDBTag ¶
func GetDBTag(field reflect.StructField) string
func GetJSONOrDBTag ¶
func GetJSONOrDBTag(field reflect.StructField) string
Get json or db tag from a struct. First try to get JSON tag, if not exist get the DB tag. If not exist, return empty string.
func GetJSONTag ¶
func GetJSONTag(field reflect.StructField) string
Get json only tag First try to get JSON tag, if not exist get the DB tag. If not exist, return empty string.
func GetType ¶
Get Struct Type (or any types, but mostly using this to get what type of struct) in generics functions removeDots will remove the filename.[structName] and return only structName
func Int ¶
Faster Atoi, only for string number that is less than 10 digits. No error checking, if there is error, then return 0. Skipping the decimals (anything after . like: 123.123 ==> 123) Ignoring the thousand separator abs = true, return only absolute value. NOTE: only works on round numbers (integer) cannot be decimals
func IntPlus ¶
PLEASE NOTE TO USE THIS ONLY IF YOU ARE SURE THAT THE STRING IS INTEGER Mostly only to convert simple string index back to positive integer NOTE: only works on decimals and POSITIVE value, so string "-123" will not work
func LastStringAfterDelimiter ¶
Return the last string s after delimiter d, example: s='this;is;delimited;by;semicolon' and d=';' then this function return "semicolon"
func MapToStringSlice ¶
NOTE: For debugging usually Use this to log/print map into key: value array of string
func MapToStruct ¶
This can be written using reflect and loop through the fields and json tag. But marshall works as well
func MapToStructSlow ¶
MapToStruct that convert map to struct with key defined in `json` tag
func MapToStructSlowDB ¶
MapToStruct that convert map to struct with key defined in `json` tag
func MapToStructSlowJSON ¶
MapToStruct that convert map to struct with key defined in `json` tag
func MaxMinIntArray ¶
Return the maximum, Minimum values and index in the array of integer
func StringContainsSplitBySpace ¶
str is multiple value separated by space, ie: str="token id_token" cannot use contain because rtype="token" might hit id_token as well
func StringSliceDebug ¶
NOTE: Not USED! Use this to log/print array of string combined with DEBUG_SEPARATOR
func StructToMap ¶
StructToMap converts a struct to a map using generics with JSON or DB tags and default options
func StructToMapDB ¶
StructToMapDB converts a struct to a map with DB tags and default options
func StructToMapDBWithOptions ¶
func StructToMapDBWithOptions[T any](input T, opts MapOptions) map[string]interface{}
StructToMapDBWithOptions converts a struct to a map with DB tags and custom options
func StructToMapJSON ¶
StructToMapJSON converts a struct to a map with JSON tags and default options
func StructToMapJSONWithOptions ¶
func StructToMapJSONWithOptions[T any](input T, opts MapOptions) map[string]interface{}
StructToMapJSONWithOptions converts a struct to a map with JSON tags and custom options
func StructToMapWithOptions ¶
func StructToMapWithOptions[T any](input T, opts MapOptions) map[string]interface{}
StructToMapWithOptions converts a struct to a map using generics with JSON or DB tags and custom options
Types ¶
type MapOptions ¶
type MapOptions struct {
SkipZeroNumbers bool // Skip integers/floats that are 0
SkipEmptyStrings bool // Skip strings that are empty
SkipFalseBools bool // Skip booleans that are false
SkipZeroTimes bool // Skip time.Time that are zero (Jan 1, 0001 UTC)
SkipEmptySlices bool // Skip empty slices and arrays
SkipEmptyMaps bool // Skip empty maps
SkipNilPointers bool // Skip nil pointers (always true, included for completeness)
TimeFormat string // Format to use for time.Time values (empty string uses time.RFC3339)
}
MapOptions defines options for structure to map conversion
func DefaultNoSkipMapOptions ¶
func DefaultNoSkipMapOptions() MapOptions
Can also use this for non-skipping the zero and all, usually we want to set 0 to the integer like saving in DB, so usage would be:
resultMap := StructToMapDBWithOptions[StructName](struct_object, DefaultNoSkipMapOptions())
DefaultSkipMapOptions returns the default options for map conversion
func DefaultSkipMapOptions ¶
func DefaultSkipMapOptions() MapOptions
DefaultSkipMapOptions returns the default options for map conversion