From 1e1c13a5180f09de731d69357f1a0e8135ba9eda Mon Sep 17 00:00:00 2001 From: jano3 <jano@bob.co.za> Date: Fri, 16 Feb 2024 15:16:18 +0200 Subject: [PATCH] Ignore empty arrays for non-string query parameter fields --- struct_utils/named_values_to_struct.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/struct_utils/named_values_to_struct.go b/struct_utils/named_values_to_struct.go index 9786120..a7dfeb1 100644 --- a/struct_utils/named_values_to_struct.go +++ b/struct_utils/named_values_to_struct.go @@ -263,6 +263,10 @@ func unmarshalNamedValuesIntoStructPtr(prefix string, namedValues map[string][]s if structTypeField.Type.Kind() == reflect.Slice { // this param struct field is a slice, iterate over all specified values for i, fieldValue := range fieldValues { + if fieldValue == "[]" && structTypeField.Type.Elem().Kind() != reflect.String { + // empty array - do nothing + continue + } parsedValue, parseErr := unmarshalValue(fieldValue, structTypeField.Type.Elem()) if parseErr != nil { err = errors.Wrapf(parseErr, "invalid %s[%d]", fieldName, i) -- GitLab