Ai
1 Star 0 Fork 0

pretty_tech/xby_golang

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
DockerInspectHelper.go 854 Bytes
一键复制 编辑 原始数据 按行查看 历史
buou1985 提交于 2021-01-07 11:24 +08:00 . 1
package helper
import (
"encoding/json"
"fmt"
)
var index = 0
var keys = make([]string, 0)
func getDcValueSingle(source map[string]interface{}) string {
if index > len(keys)-1 {
return ""
}
if v, ok := source[keys[index]]; ok {
if vString, ok := v.(string); ok {
return vString
} else if vMap, ok := v.(map[string]interface{}); ok {
index++
return getDcValueSingle(vMap)
}
}
return ""
}
func GetDcValueByKeys(source string, keysParam ...string) string {
var des []interface{}
//fmt.Println("des:", des)
index = 0
keys = keysParam
err := json.Unmarshal([]byte(source), &des)
if err != nil {
Fatal(fmt.Errorf("unmarshal wrong"), "__GetDcValueByKey")
}
if s, ok := des[0].(map[string]interface{}); ok {
return getDcValueSingle(s)
} else {
Fatal(fmt.Errorf("unmarshal empty"), "__GetDcValueByKey")
}
return ""
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/pretty_tech/xby_golang.git
git@gitee.com:pretty_tech/xby_golang.git
pretty_tech
xby_golang
xby_golang
v0.1.3

搜索帮助