From 5741ec597b1fe4d9b5bcc68c810da23f1cad9117 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 2 Mar 2020 22:24:36 +0100 Subject: [PATCH] [breaking] do not return first element of 1-sized slices as it, return a slice - it is more consistent and does not rely of a "hidden" assomption. - for consistency, it is also a better practice to always the same type when waiting to receive a slice ; the 1 element case should not break anything --- internal/reqdata/parameter.go | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/internal/reqdata/parameter.go b/internal/reqdata/parameter.go index 09d48a3..033cbfe 100644 --- a/internal/reqdata/parameter.go +++ b/internal/reqdata/parameter.go @@ -66,27 +66,12 @@ func parseParameter(data interface{}) (interface{}, error) { /* (1) []string -> recursive */ case reflect.Slice: - // 1. Return nothing if empty + // 1. ignore empty if dvalue.Len() == 0 { return data, nil } - // 2. only return first element if alone - if dvalue.Len() == 1 { - - element := dvalue.Index(0) - - // try to parse if a string (containing json) - if element.Kind() == reflect.String { - return parseParameter(element.String()) - } - - // already typed - return element.Interface(), nil - - } - - // 3. Return all elements if more than 1 + // 2. parse each element recursively result := make([]interface{}, dvalue.Len()) for i, l := 0, dvalue.Len(); i < l; i++ {