mirror of
https://github.com/adnanh/webhook.git
synced 2025-05-22 05:20:24 +00:00
Merge 060f5b6dd6
into 1b13355196
This commit is contained in:
commit
12a2466052
2 changed files with 17 additions and 7 deletions
|
@ -394,14 +394,22 @@ func GetParameter(s string, params interface{}) (interface{}, error) {
|
||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checked for dotted references
|
// Check for dotted references
|
||||||
p := strings.SplitN(s, ".", 2)
|
p := strings.Split(s, ".")
|
||||||
if pValue, ok := params.(map[string]interface{})[p[0]]; ok {
|
ref := ""
|
||||||
if len(p) > 1 {
|
for i := range p {
|
||||||
return GetParameter(p[1], pValue)
|
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
|
return pValue, nil
|
||||||
|
} else {
|
||||||
|
return GetParameter(strings.Join(p[i+1:], "."), pValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -231,6 +231,8 @@ var extractParameterTests = []struct {
|
||||||
{"b", map[string]interface{}{"b": map[string]interface{}{"z": 1}}, `{"z":1}`, true},
|
{"b", map[string]interface{}{"b": map[string]interface{}{"z": 1}}, `{"z":1}`, true},
|
||||||
{"c", map[string]interface{}{"c": []interface{}{"y", "z"}}, `["y","z"]`, true},
|
{"c", map[string]interface{}{"c": []interface{}{"y", "z"}}, `["y","z"]`, true},
|
||||||
{"d", map[string]interface{}{"d": [2]interface{}{"y", "z"}}, `["y","z"]`, true},
|
{"d", map[string]interface{}{"d": [2]interface{}{"y", "z"}}, `["y","z"]`, true},
|
||||||
|
{"a.b.c.1", map[string]interface{}{"a": map[string]interface{}{"b": map[string]interface{}{"c.1": "z"}}}, "z", true},
|
||||||
|
{"a.b.1.c", map[string]interface{}{"a": map[string]interface{}{"b.1": map[string]interface{}{"c": "z"}}}, "z", true},
|
||||||
// failures
|
// failures
|
||||||
{"check_nil", nil, "", false},
|
{"check_nil", nil, "", false},
|
||||||
{"a.X", map[string]interface{}{"a": map[string]interface{}{"b": "z"}}, "", false}, // non-existent parameter reference
|
{"a.X", map[string]interface{}{"a": map[string]interface{}{"b": "z"}}, "", false}, // non-existent parameter reference
|
||||||
|
|
Loading…
Add table
Reference in a new issue