无法解析Golang映射和嵌套json



我有下面的片段


func fakeGetInclusterConfig() (*corev1.ConfigMap, error) {
configMap := &corev1.ConfigMap{
Data: map[string]map[string]string{"cluster-config.json":{
"cluster_id":"xxx",
"cluster_name":"yyy",
"cluster_type":"zzz",
"cluster_pay_tier":"paid",
},
},
}
return configMap, nil
}

但是Data部分存在一些问题。我无法正确声明类型。我尝试了所有我知道的选项,但显然不是正确的。请有人在这里帮忙

主代码期望

configmap, err := cm.GetConfigMap(handler.k8sclient, Configmap, ConfigmapNS)
clusterConfigJSON := configmap.Data["cluster-config.json"]
clusterConfigJSON = strings.Replace(clusterConfigJSON, "n", "", -1)
clusterConfigJSON = strings.Replace(clusterConfigJSON, " ", "", -1)
var clusterConfigInfo clusterInfo
err = json.Unmarshal([]byte(clusterConfigJSON), &clusterConfigInfo)
if err != nil {

所以我想要一个用于cluster-config.json密钥的json结构。我正在尝试为测试用例创建伪数据。

我可以用这种方式修复

clusterDetails := `{"cluster_id":"xxx","cluster_name":"yyy","cluster_type":"kkk","cluster_pay_tier":"paid","datacenter": "dal","account_id": "mmm","created": "2021-11-23T07:18:25+0000","name": "tokreleasetest","master_public_url": "https://xxx.containers.cloud.nnn.com:1111","master_url": "https://c106.dal-tok.containers.cloud.nnn.com:1111","crn":  "crn:v1:bluemix:public:containers-kubernetes:dal-tok:2334445:cdfr343"}`
configMap := &corev1.ConfigMap{
Data: map[string]string{"cluster-config.json":clusterDetails},
}

相关内容

  • 没有找到相关文章

最新更新