1 回答
TA贡献1796条经验 获得超4个赞
一些修改建议:
// Once you have the configMap, check whether cm1.yaml file exist or not?
var cmFile string
if value, ok:= cm.Data["cm1.yaml"]; ok {
cmFile = value
}
// while unmarshal-ing yaml files, use map[string]interface
// otherwise error may occur.
// Case:
//| a:
//| b: value
//| c:
//| d: value2
cmData := make(map[string]interface{})
err := yaml.Unmarshal([]byte(cmFile), cmData)
if err != nil {
return errors.New("error occurred")
}
var apiVersion string
// Check whether the "rzr" exist or not
if value, ok := cmData["rzr"]; ok {
// convert the value from interface to string
// using type assertion.
stringValue, valid := value.(string)
// if successfully converted to string
if valid {
apiVersion = strings.ReplaceAll(stringValue, ".", "-")
} else {
return errors.New("failed to convert")
}
}
- 1 回答
- 0 关注
- 144 浏览
添加回答
举报