mirror of
https://github.com/TwiN/gatus.git
synced 2025-01-24 23:08:58 +01:00
Clean up code for len() function
This commit is contained in:
parent
43aa31be58
commit
f930687b4a
@ -13,6 +13,9 @@ const (
|
|||||||
ResponseTimePlaceHolder = "[RESPONSE_TIME]"
|
ResponseTimePlaceHolder = "[RESPONSE_TIME]"
|
||||||
BodyPlaceHolder = "[BODY]"
|
BodyPlaceHolder = "[BODY]"
|
||||||
|
|
||||||
|
LengthFunctionPrefix = "len("
|
||||||
|
FunctionSuffix = ")"
|
||||||
|
|
||||||
InvalidConditionElementSuffix = "(INVALID)"
|
InvalidConditionElementSuffix = "(INVALID)"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -34,9 +37,9 @@ func sanitizeAndResolve(list []string, result *Result) []string {
|
|||||||
// if starts with BodyPlaceHolder, then evaluate json path
|
// if starts with BodyPlaceHolder, then evaluate json path
|
||||||
if strings.Contains(element, BodyPlaceHolder) {
|
if strings.Contains(element, BodyPlaceHolder) {
|
||||||
wantLength := false
|
wantLength := false
|
||||||
if strings.HasPrefix(element, "len(") && strings.HasSuffix(element, ")") {
|
if strings.HasPrefix(element, LengthFunctionPrefix) && strings.HasSuffix(element, FunctionSuffix) {
|
||||||
wantLength = true
|
wantLength = true
|
||||||
element = strings.TrimSuffix(strings.TrimPrefix(element, "len("), ")")
|
element = strings.TrimSuffix(strings.TrimPrefix(element, LengthFunctionPrefix), FunctionSuffix)
|
||||||
}
|
}
|
||||||
resolvedElement, resolvedElementLength, err := jsonpath.Eval(strings.Replace(element, fmt.Sprintf("%s.", BodyPlaceHolder), "", 1), result.Body)
|
resolvedElement, resolvedElementLength, err := jsonpath.Eval(strings.Replace(element, fmt.Sprintf("%s.", BodyPlaceHolder), "", 1), result.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user