-- 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) []string
SSKeysStartedWith retrieve all keys started with
func ToJson(hash map[string]any) string
ToJson 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) []byte
ToMsgp 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 string
const (
RawFieldName FieldTag = ``
SnakeFieldName FieldTag = `SNAKE`
CamelFieldName FieldTag = `CAMEL`
AllFieldName FieldTag = `ALL`
)
type IAX map[int64][]any
IAX map with int64 key and array of any value
type IB map[int64]bool
IB map with int64 key and bool value
func (hash IB) Keys() []int64
Keys 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) string
KeysConcat 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]int64
II map with int64 key and int64 value
func (hash II) Keys() []int64
Keys get array of int64 keys
m := M.II{1:1,2:3}
m.Keys() // []int64{1, 2}
func (hash II) KeysConcat(with string) string
KeysConcat 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]string
IS map with int64 key and string value
type IX map[int64]any
IX map with int64 key and any value
func (hash IX) Keys() []int64
Keys get array of int64 keys
m := M.IX{1:1,2:`DIA`}
m.Keys()) // []int64{1, 2}
func (hash IX) ToSX() SX
ToSX 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][]any
SAX map with string key and array of any value
type SB map[string]bool
SB 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) string
KeysConcat get concatenated string keys
m := M.SB{`tes`:true,`coba`:true,`lah`:true}
m.KeysConcat(`,`) // `coba,lah,tes`
func (hash SB) SortedKeys() []string
SortedKeys get sorted keys
m := M.SS{`tes`:true,`coba`:false,`lah`:false}
m.SortedKeys() // []string{`coba`,`lah`,`tes`}
func (hash SB) ToJson() string
ToJson convert to json string, silently print error if failed
func (hash SB) ToJsonPretty() string
ToJsonPretty convert to pretty json string, silently print error if failed
func (hash SB) ToMsgp() []byte
ToMsgp convert to msgpack string, silently print error if failed
type SF map[string]float64
SF map with string key and float64 value
type SI map[string]int64
SI map with string key and int64 value
type SS map[string]string
SS map with string key and string value
func (hash SS) GetFloat(key string) float64
GetFloat get float64 type from map
func (hash SS) GetInt(key string) int64
GetInt get int64 from from map
func (hash SS) GetStr(key string) string
GetStr get string type from map
func (hash SS) GetUint(key string) uint64
GetUint get uint from map
func (hash SS) Keys() []string
Keys get array of string keys
m := M.SS{`satu`:`1`,`dua`:`2`}
m.Keys() // []string{"satu", "dua"}
func (hash SS) KeysConcat(with string) string
KeysConcat 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) string
Pretty get pretty printed values
func (hash SS) PrettyFunc(sep string, fun func(string, string) string) string
PrettyFunc get pretty printed values with filter values
func (hash SS) SortedKeys() []string
SortedKeys get sorted keys
m := M.SS{`tes`:`tes`,`coba`:`saja`,`lah`:`lah`}
m.SortedKeys() // []string{`coba`,`lah`,`tes`}
func (hash SS) ToJson() string
ToJson convert to json string, silently print error if failed
func (hash SS) ToMsgp() []byte
ToMsgp convert to msgpack string, silently print error if failed
func (hash SS) ToScylla() string
ToScylla convert to scylla based map<text,text>
type SX map[string]any
SX map with string key and any value
func FromStruct(srcStructPtr any) SX
FromStruct 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) []any
GetAX 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) bool
GetBool 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) float64
GetFloat 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) int64
GetInt 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) []int64
GetIntArr 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) IB
GetMIB 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) SB
GetMSB 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) SF
GetMSF 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) SI
GetMSI 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) SX
GetMSX 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) string
GetStr 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) uint64
GetUint 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() []string
Keys get array of string keys
m := M.SS{`satu`:`1`,`dua`:`2`}
m.Keys() // []string{"satu", "dua"}
func (hash SX) Pretty(sep string) string
Pretty get pretty printed values
func (hash SX) Set(key string, val any)
Set set key with any value
func (hash SX) SortedKeys() []string
SortedKeys get sorted keys
m := M.SX{`tes`:1,`coba`:12.4,`lah`:false}
m.SortedKeys() // []string{`coba`,`lah`,`tes`}
func (hash SX) ToJson() string
ToJson convert to json string, silently print error if failed
func (hash SX) ToJsonPretty() string
ToJsonPretty convert to pretty json string, silently print error if failed
func (hash SX) ToMsgp() []byte
ToMsgp 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) *StructMapper
StructMap get or create a struct mapper
func (sm *StructMapper) MapToStruct(m SX, s any)
func (sm *StructMapper) StructToMap(s any) (m SX)