增加数据合并能力

This commit is contained in:
白茶清欢 2024-01-10 17:01:08 +08:00
parent c5395eec5e
commit cb0f7b9151

49
json.go
View File

@ -123,6 +123,55 @@ func (oj *ownJSON) Transition(input interface{}, receiver interface{}) error {
return oj.UnmarshalWithNumber(oj.MarshalForByte(input), receiver) return oj.UnmarshalWithNumber(oj.MarshalForByte(input), receiver)
} }
// TransitionIgnoreError ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:57 2024/1/10
func (oj *ownJSON) TransitionIgnoreError(input interface{}, receiver interface{}) {
_ = oj.UnmarshalWithNumber(oj.MarshalForByte(input), receiver)
}
// MergeDataForMap 合并数据到map
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:48 2024/1/10
func (oj *ownJSON) MergeDataForMap(ignoreError bool, dataList ...interface{}) (map[string]interface{}, error) {
res := make(map[string]interface{})
for _, data := range dataList {
if nil == data {
continue
}
var (
err error
itemRes map[string]interface{}
)
if err = oj.Transition(data, &itemRes); nil != err {
if ignoreError {
continue
}
return res, err
}
for k, v := range itemRes {
res[k] = v
}
}
return res, nil
}
// MergeDataForMapIgnoreError 多个数据合并到一个Map
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:00 2024/1/10
func (oj *ownJSON) MergeDataForMapIgnoreError(dataList ...interface{}) map[string]interface{} {
res, _ := oj.MergeDataForMap(true, dataList)
return res
}
// ConsoleOutput ... // ConsoleOutput ...
// //
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>