|
|
- package helper
-
- import (
- "errors"
- )
-
- func MergeStringMap(x, y map[string]string) map[string]string {
-
- n := make(map[string]string)
- for i, v := range x {
- for j, w := range y {
- if i == j {
- n[i] = w
-
- } else {
- if _, ok := n[i]; !ok {
- n[i] = v
- }
- if _, ok := n[j]; !ok {
- n[j] = w
- }
- }
- }
- }
-
- return n
-
- }
-
- /**
- * 转换为map string数组
- * 2021/1/5
- * gz
- */
- func ToMapStringArray(x interface{}) ([]map[string]string, error) {
- list, ok := x.([]interface{})
- if !ok {
- return []map[string]string{}, errors.New("type error")
- }
-
- if len(list) < 1 {
- return []map[string]string{}, nil
- }
- var ret []map[string]string = make([]map[string]string, len(list))
- var tmp map[string]interface{}
- var map_tmp map[string]string
- var err error
-
- for key, item := range list {
- if tmp, ok = item.(map[string]interface{}); ok {
- map_tmp = make(map[string]string)
- for k, v := range tmp {
- map_tmp[k] = ToStr(v)
- }
- ret[key] = map_tmp
- } else {
- err = errors.New("data type error")
- break
- }
- }
-
- return ret, err
- }
|