- 美团外卖满减,直降,运费活动API完成

This commit is contained in:
gazebo
2019-04-03 22:01:17 +08:00
parent f105cfed62
commit 21818bd78d
6 changed files with 365 additions and 58 deletions

View File

@@ -481,6 +481,10 @@ func Struct2MapWithIgnore(obj interface{}, ignoreValues map[string]interface{})
return mapData
}
// 注意如下两个函数的行为与标准的json.Marshal的行为是有区别的
// 这两个函数只要成员是对象或map不是指针都会被展开
// 而json.Marshal不是这样的只会展开内嵌的包括指针
// 所以原则是不用map的对象行为就比较一致
func MarshalJSONIgnoreValues(obj interface{}, ignoreValues map[string]interface{}) ([]byte, error) {
return json.Marshal(Struct2MapWithIgnore(obj, ignoreValues))
}
@@ -488,3 +492,12 @@ func MarshalJSONIgnoreValues(obj interface{}, ignoreValues map[string]interface{
func MustMarshalJSONIgnoreValues(obj interface{}, ignoreValues map[string]interface{}) []byte {
return MustMarshal(Struct2MapWithIgnore(obj, ignoreValues))
}
func StructList2MapListWithIgnore(obj interface{}, ignoreValues map[string]interface{}) (mapList []map[string]interface{}) {
objList := Interface2Slice(obj)
mapList = make([]map[string]interface{}, len(objList))
for k, v := range objList {
mapList[k] = Struct2MapWithIgnore(v, ignoreValues)
}
return mapList
}