Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Log an error if a non-64 datatype is used. #270

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion bucketing/segmentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bucketing

import (
"fmt"
"github.com/devcyclehq/go-server-sdk/v2/util"
"math"
"regexp"
"strings"
Expand Down Expand Up @@ -57,7 +58,30 @@ func checkCustomData(filter *CustomDataFilter, data map[string]interface{}, clie
} else {
dataValue = data[filter.DataKey]
}

isNot64Bit := false
switch dataValue.(type) {
case uint8:
isNot64Bit = true
case uint16:
isNot64Bit = true
case uint32:
isNot64Bit = true
case uint:
isNot64Bit = true
case int8:
isNot64Bit = true
case int16:
isNot64Bit = true
case int32:
isNot64Bit = true
case int:
isNot64Bit = true
case float32:
isNot64Bit = true
}
if isNot64Bit {
util.Errorf("Custom data key %s is not a 64 bit type. Please use a 64 bit type", filter.DataKey)
}
if operator == "exist" {
return checkValueExists(dataValue)
} else if operator == "!exist" {
Expand All @@ -68,6 +92,7 @@ func checkCustomData(filter *CustomDataFilter, data map[string]interface{}, clie
} else {
return checkStringsFilter(v, filter.UserFilter)
}

} else if _, ok := dataValue.(float64); ok && filter.DataKeyType == "Number" {
return checkNumbersFilterJSONValue(dataValue, filter.UserFilter)
} else if v, ok := dataValue.(bool); ok && filter.DataKeyType == "Boolean" {
Expand Down
Loading