-- import "github.com/kokizzu/gotro/M"
func FastestCopyStruct(s, d any)FastestCopyStruct target can be struct or map
func FastestMapToStruct(m any, s any)FastestMapToStruct only for exact match of field name and map key
func FastestStructToMap(s any) (m map[string]any)FastestStructToMap using struct's field name as map key
func SSKeysStartedWith(m SS, prefix string) []stringSSKeysStartedWith retrieve all keys started with
func ToJson(hash map[string]any) stringToJson convert map[string]any to json
m := map[string]any{`buah`:123,`angka`:`dia`}
M.ToJson(m) // {"angka":"dia","buah":123}
func ToMsgp(hash map[string]any) []byteToMsgp convert map[string]any to json
m := map[string]any{`buah`:123,`angka`:`dia`}
M.ToMsgp(m) // []byte{0x82, 0xa5, 0x61, 0x6e, 0x67, 0x6b, 0x61, 0xa3, 0x64, 0x69, 0x61, 0xa5, 0x62, 0x75, 0x61, 0x68, 0xcd, 0x7b}
type FieldTag stringconst (
RawFieldName FieldTag = ``
SnakeFieldName FieldTag = `SNAKE`
CamelFieldName FieldTag = `CAMEL`
AllFieldName FieldTag = `ALL`
)type IAX map[int64][]anyIAX map with int64 key and array of any value
type IB map[int64]boolIB map with int64 key and bool value
func (hash IB) Keys() []int64Keys get array of int64 keys
m := M.IB{1:true,2:false}
m.Keys() // []int64{1, 2}
get all integer keys
func (hash IB) KeysConcat(with string) stringKeysConcat get concatenated integer keys
m := M.IB{1: true, 2: false, 3:true, 5:false}
m.KeysConcat(`,`) // `1,2,3,5`
type II map[int64]int64II map with int64 key and int64 value
func (hash II) Keys() []int64Keys get array of int64 keys
m := M.II{1:1,2:3}
m.Keys() // []int64{1, 2}
func (hash II) KeysConcat(with string) stringKeysConcat get concatenated integer keys
m := M.II{1: 2, 2: 567, 3:6, 5:45}
m.KeysConcat(`,`) // `1,2,3,5`
type IS map[int64]stringIS map with int64 key and string value
type IX map[int64]anyIX map with int64 key and any value
func (hash IX) Keys() []int64Keys get array of int64 keys
m := M.IX{1:1,2:`DIA`}
m.Keys()) // []int64{1, 2}
func (hash IX) ToSX() SXToSX convert keys to string
m := M.IX{1:1,2:`DUA`}
m.ToSX() // M.SX{"1": int(1),"2": "DUA"}
convert integer keys to string keys
type SAX map[string][]anySAX map with string key and array of any value
type SB map[string]boolSB map with string key and bool value
func (hash SB) IntoJson() (string, bool)IntoJson convert to json string with check
func (hash SB) IntoJsonPretty() (string, bool)convert to pretty json string with check
func (hash SB) IntoMsgp() ([]byte, bool)IntoMsgp convert to msgpack string with check
func (hash SB) KeysConcat(with string) stringKeysConcat get concatenated string keys
m := M.SB{`tes`:true,`coba`:true,`lah`:true}
m.KeysConcat(`,`) // `coba,lah,tes`
func (hash SB) SortedKeys() []stringSortedKeys get sorted keys
m := M.SS{`tes`:true,`coba`:false,`lah`:false}
m.SortedKeys() // []string{`coba`,`lah`,`tes`}
func (hash SB) ToJson() stringToJson convert to json string, silently print error if failed
func (hash SB) ToJsonPretty() stringToJsonPretty convert to pretty json string, silently print error if failed
func (hash SB) ToMsgp() []byteToMsgp convert to msgpack string, silently print error if failed
type SF map[string]float64SF map with string key and float64 value
type SI map[string]int64SI map with string key and int64 value
type SS map[string]stringSS map with string key and string value
func (hash SS) GetFloat(key string) float64GetFloat get float64 type from map
func (hash SS) GetInt(key string) int64GetInt get int64 from from map
func (hash SS) GetStr(key string) stringGetStr get string type from map
func (hash SS) GetUint(key string) uint64GetUint get uint from map
func (hash SS) Keys() []stringKeys get array of string keys
m := M.SS{`satu`:`1`,`dua`:`2`}
m.Keys() // []string{"satu", "dua"}
func (hash SS) KeysConcat(with string) stringKeysConcat get concatenated string keys
m := M.SS{`tes`:`tes`,`coba`:`saja`,`lah`:`lah`}
m.KeysConcat(`,`) // `coba,lah,tes`
func (hash SS) Merge(src SS)Merge merge from another map
func (hash SS) Pretty(sep string) stringPretty get pretty printed values
func (hash SS) PrettyFunc(sep string, fun func(string, string) string) stringPrettyFunc get pretty printed values with filter values
func (hash SS) SortedKeys() []stringSortedKeys get sorted keys
m := M.SS{`tes`:`tes`,`coba`:`saja`,`lah`:`lah`}
m.SortedKeys() // []string{`coba`,`lah`,`tes`}
func (hash SS) ToJson() stringToJson convert to json string, silently print error if failed
func (hash SS) ToMsgp() []byteToMsgp convert to msgpack string, silently print error if failed
func (hash SS) ToScylla() stringToScylla convert to scylla based map<text,text>
type SX map[string]anySX map with string key and any value
func FromStruct(srcStructPtr any) SXFromStruct convert any struct to map
func (hash *SX) FromJson(str string) (ok bool)FromJson convert string to map, silently print error if failed doesn't overwrite existing value if json doesn't have the same key returns true if ok
func (json SX) GetAX(key string) []anyGetAX get array of anything value from map
m := M.SX{`tes`:[]any{123,`buah`}}
m.GetAX(`tes`) // []interface {}{int(123),"buah"}
func (json SX) GetBool(key string) boolGetBool get bool type from map (empty string, 0, f, false are false, other
non empty are considered truthy value) m :=
M.SX{test:234.345,coba:buah,angka:float64(123),salah:123}
m.GetBool(`test`) // bool(true)
m.GetBool(`coba`) // bool(true)
m.GetBool(`angka`) // bool(true)
m.GetBool(`salah`) // bool(false)
func (json SX) GetFloat(key string) float64GetFloat get float64 type from map
m := M.SX{`test`:234.345,`coba`:`buah`,`dia`:true,`angka`:23435}
m.GetFloat(`test`) // float64(234.345)
m.GetFloat(`dia`) // int64(1)
m.GetFloat(`coba`) // 0
m.GetFloat(`angka`) // 0
func (json SX) GetInt(key string) int64GetInt get int64 type from map
m := M.SX{`test`:234.345,`coba`:`buah`,`dia`:true,`angka`:int64(23435)}
m.GetInt(`test`)) // int64(234)
m.GetInt(`dia`)) // int64(1)
m.GetInt(`coba`)) // int64(0)
m.GetInt(`angka`)) // int64(23435)
func (json SX) GetIntArr(key string) []int64GetIntArr get array int64 value from map
m := M.SX{`tes`:[]int64{123,234}}
m.GetIntArr(`tes`)) // []int64{123, 234}
func (json SX) GetMIB(key string) IBGetMIB get map string int64 value from map
m := M.SX{`tes`:M.SB{`satu`:true,`2`:false}}
m.GetMSB(`tes`) // M.SB{"satu":true, "2":false}
func (json SX) GetMSB(key string) SBGetMSB get map string bool value from map
m := M.SX{`tes`:M.SB{`1`:true,`2`:false}}
m.GetMSB(`tes`) // M.SB{"1":true, "2":false}
func (json SX) GetMSF(key string) SFGetMSF get map string float64 value from map
m := M.SX{`tes`:M.SF{`satu`:32.45,`2`:12}}
m.GetMSF(`tes`) // M.SF{"satu":32.45, "2":12}
func (json SX) GetMSI(key string) SIGetMSI get map string int64 value from map
m := M.SX{`tes`:M.SF{`satu`:32,`2`:12}}
m.GetMSI(`tes`) // M.SF{"satu":32, "2":12}
func (json SX) GetMSX(key string) SXGetMSX get map string anything value from map
m := M.SX{`tes`:M.SX{`satu`:234.345,`dua`:`huruf`,`tiga`:123}}
m.GetMSX(`tes`) // M.SX{"tiga": int(123),"satu": float64(234.345),"dua": "huruf"}
func (json SX) GetStr(key string) stringGetStr get string type from map
m := M.SX{`test`:234.345,`coba`:`buah`,`angka`:int64(123)}
m.GetStr(`test`) // `234.345`
m.GetStr(`coba`) // `buah`
m.GetStr(`angka`) // `123`
func (json SX) GetUint(key string) uint64GetUint get uint type from map
m := M.SX{`test`:234.345,`coba`:`buah`,`dia`:true,`angka`:int64(23435)}
m.GetInt(`test`)) // int64(234)
m.GetInt(`dia`)) // int64(1)
m.GetInt(`coba`)) // int64(0)
m.GetInt(`angka`)) // int64(23435)
func (hash SX) IntoJson() (string, bool)IntoJson convert to json string with check
func (hash SX) IntoJsonPretty() (string, bool)IntoJsonPretty convert to pretty json string with check
func (hash SX) IntoMsgp() ([]byte, bool)IntoMsgp convert to msgpack string with check
func (hash SX) Keys() []stringKeys get array of string keys
m := M.SS{`satu`:`1`,`dua`:`2`}
m.Keys() // []string{"satu", "dua"}
func (hash SX) Pretty(sep string) stringPretty get pretty printed values
func (hash SX) Set(key string, val any)Set set key with any value
func (hash SX) SortedKeys() []stringSortedKeys get sorted keys
m := M.SX{`tes`:1,`coba`:12.4,`lah`:false}
m.SortedKeys() // []string{`coba`,`lah`,`tes`}
func (hash SX) ToJson() stringToJson convert to json string, silently print error if failed
func (hash SX) ToJsonPretty() stringToJsonPretty convert to pretty json string, silently print error if failed
func (hash SX) ToMsgp() []byteToMsgp convert to msgpack string, silently print error if failed
func (m SX) ToStruct(targetStructPtr any)ToStruct convert to struct
type StructMapper struct {
StructName string
Offset2key map[uintptr]string
Key2offset map[string]uintptr
}func ParseStruct(s any, tag FieldTag) (sm *StructMapper)ParseStruct convert struct to structMapper
func StructMap(structPtr any) *StructMapperStructMap get or create a struct mapper
func (sm *StructMapper) MapToStruct(m SX, s any)func (sm *StructMapper) StructToMap(s any) (m SX)