Merge pull request #6 from AdrieVanDijk/dotted-reference-fix

fix 'err:parameter node not found'when a dotted reference is not the …
This commit is contained in:
Su Yang 2023-01-09 22:16:46 +08:00 committed by GitHub
commit 5cb0bc7ca9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

View file

@ -394,14 +394,22 @@ func GetParameter(s string, params interface{}) (interface{}, error) {
return v, nil
}
// Checked for dotted references
p := strings.SplitN(s, ".", 2)
if pValue, ok := params.(map[string]interface{})[p[0]]; ok {
if len(p) > 1 {
return GetParameter(p[1], pValue)
// Check for dotted references
p := strings.Split(s, ".")
ref := ""
for i := range p {
if i == 0 {
ref = p[i]
} else {
ref += "." + p[i]
}
if pValue, ok := params.(map[string]interface{})[ref]; ok {
if i == len(p)-1 {
return pValue, nil
} else {
return GetParameter(strings.Join(p[i+1:], "."), pValue)
}
}
return pValue, nil
}
}