代码拉取完成,页面将自动刷新
/*
Copyright 2019 The Vearch Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreedto in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package util
import (
"strings"
)
func GetOrDefault(mapinterface *map[string]interface{}, k string, dv interface{}) interface{} {
if v := (*mapinterface)[k]; v != nil {
return v
} else {
return dv
}
}
//make map to level 1 example map[a][b]=1 it wil map[a.b]=1
func DrawMap(maps map[string]interface{}, split string) map[string]interface{} {
newMap := make(map[string]interface{})
drawMap(newMap, maps, "", split)
return newMap
}
func drawMap(result, maps map[string]interface{}, prefix, split string) {
newPrefix := prefix
for k, v := range maps {
if prefix == "" {
newPrefix = k
} else {
newPrefix = prefix + split + k
}
switch v.(type) {
case map[string]interface{}:
drawMap(result, v.(map[string]interface{}), newPrefix, split)
default:
result[newPrefix] = v
}
}
}
//make map to level 1 example map[a.b]=1 it will map[a][b]=1
func AssembleMap(maps map[string]interface{}, split string) map[string]interface{} {
newMap := make(map[string]interface{})
for k, v := range maps {
split := strings.Split(k, split)
var temp interface{}
pre := newMap
for i := 0; i < len(split)-1; i++ {
temp = pre[split[i]]
if temp == nil {
temp = make(map[string]interface{})
pre[split[i]] = temp.(map[string]interface{})
}
pre = temp.(map[string]interface{})
}
pre[split[len(split)-1]] = v
}
return newMap
}
/**
deep merge src to dest
*/
func MergeMap(dest, src map[string]interface{}) {
for k, v := range src {
switch v.(type) {
case map[string]interface{}:
if descV, ok := dest[k]; ok {
if descVmap, cOk := descV.(map[string]interface{}); cOk {
MergeMap(descVmap, v.(map[string]interface{}))
} else {
dest[k] = v
}
}
default:
dest[k] = v
}
}
}
//is key in map
func MapContains(m map[string]interface{}, key string) bool {
_, ok := m[key]
return ok
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。