Refactor code

This commit is contained in:
wenxu12345
2021-12-31 08:49:05 +08:00
parent ab5faec68c
commit c8d803b559
3 changed files with 14 additions and 20 deletions
+12 -2
View File
@@ -4,11 +4,21 @@ import (
"encoding/json"
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
"reflect"
)
func JsonDataList(resp ...interface{}) []map[string]interface{} {
func JsonDataList(resp interface{}) []map[string]interface{} {
var list []proto.Message
if reflect.TypeOf(resp).Kind() == reflect.Slice {
s := reflect.ValueOf(resp)
for i := 0; i < s.Len(); i++ {
ele := s.Index(i)
list = append(list, ele.Interface().(proto.Message))
}
}
result := make([]map[string]interface{}, 0)
for _, v := range resp[0].([]proto.Message) {
for _, v := range list {
m := ProtoToMap(v, false)
result = append(result, m)
}