github.com/urso/go-structform@v0.0.2/gotype/fold_map.go (about) 1 package gotype 2 3 import ( 4 "reflect" 5 6 structform "github.com/urso/go-structform" 7 ) 8 9 var ( 10 reFoldMapBool = liftFold(map[string]bool(nil), foldMapBool) 11 reFoldMapInt = liftFold(map[string]int(nil), foldMapInt) 12 reFoldMapInt8 = liftFold(map[string]int8(nil), foldMapInt8) 13 reFoldMapInt16 = liftFold(map[string]int16(nil), foldMapInt16) 14 reFoldMapInt32 = liftFold(map[string]int32(nil), foldMapInt32) 15 reFoldMapInt64 = liftFold(map[string]int64(nil), foldMapInt64) 16 reFoldMapUint = liftFold(map[string]uint(nil), foldMapUint) 17 reFoldMapUint8 = liftFold(map[string]uint8(nil), foldMapUint8) 18 reFoldMapUint16 = liftFold(map[string]uint16(nil), foldMapUint16) 19 reFoldMapUint32 = liftFold(map[string]uint32(nil), foldMapUint32) 20 reFoldMapUint64 = liftFold(map[string]uint64(nil), foldMapUint64) 21 reFoldMapFloat32 = liftFold(map[string]float32(nil), foldMapFloat32) 22 reFoldMapFloat64 = liftFold(map[string]float64(nil), foldMapFloat64) 23 reFoldMapString = liftFold(map[string]string(nil), foldMapString) 24 ) 25 26 var tMapAny = reflect.TypeOf(map[string]interface{}(nil)) 27 28 func foldMapInterface(C *foldContext, v interface{}) error { 29 m := v.(map[string]interface{}) 30 if err := C.OnObjectStart(len(m), structform.AnyType); err != nil { 31 return err 32 } 33 34 for k, v := range m { 35 if err := C.OnKey(k); err != nil { 36 return err 37 } 38 if err := foldInterfaceValue(C, v); err != nil { 39 return err 40 } 41 } 42 return C.OnObjectFinished() 43 } 44 45 func foldMapBool(C *foldContext, v interface{}) error { 46 return C.visitor.OnBoolObject(v.(map[string]bool)) 47 } 48 49 func foldMapString(C *foldContext, v interface{}) error { 50 return C.visitor.OnStringObject(v.(map[string]string)) 51 } 52 53 func foldMapInt8(C *foldContext, v interface{}) error { 54 return C.visitor.OnInt8Object(v.(map[string]int8)) 55 } 56 57 func foldMapInt16(C *foldContext, v interface{}) error { 58 return C.visitor.OnInt16Object(v.(map[string]int16)) 59 } 60 61 func foldMapInt32(C *foldContext, v interface{}) error { 62 return C.visitor.OnInt32Object(v.(map[string]int32)) 63 } 64 65 func foldMapInt64(C *foldContext, v interface{}) error { 66 return C.visitor.OnInt64Object(v.(map[string]int64)) 67 } 68 69 func foldMapInt(C *foldContext, v interface{}) error { 70 return C.visitor.OnIntObject(v.(map[string]int)) 71 } 72 73 func foldMapUint8(C *foldContext, v interface{}) error { 74 return C.visitor.OnUint8Object(v.(map[string]uint8)) 75 } 76 77 func foldMapUint16(C *foldContext, v interface{}) error { 78 return C.visitor.OnUint16Object(v.(map[string]uint16)) 79 } 80 81 func foldMapUint32(C *foldContext, v interface{}) error { 82 return C.visitor.OnUint32Object(v.(map[string]uint32)) 83 } 84 85 func foldMapUint64(C *foldContext, v interface{}) error { 86 return C.visitor.OnUint64Object(v.(map[string]uint64)) 87 } 88 89 func foldMapUint(C *foldContext, v interface{}) error { 90 return C.visitor.OnUintObject(v.(map[string]uint)) 91 } 92 93 func foldMapFloat32(C *foldContext, v interface{}) error { 94 return C.visitor.OnFloat32Object(v.(map[string]float32)) 95 } 96 97 func foldMapFloat64(C *foldContext, v interface{}) error { 98 return C.visitor.OnFloat64Object(v.(map[string]float64)) 99 }