From 876acf1ae5e3557ae2acddbfe7fe802b120c025c Mon Sep 17 00:00:00 2001 From: Johan de Klerk <johan@shiplogic.com> Date: Thu, 3 Aug 2023 18:55:10 +0200 Subject: [PATCH] Check slice before getting values --- struct_utils/struct_utils.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/struct_utils/struct_utils.go b/struct_utils/struct_utils.go index 384feb3..4d233b6 100644 --- a/struct_utils/struct_utils.go +++ b/struct_utils/struct_utils.go @@ -15,11 +15,20 @@ func FormToKeyValuePairs(body string) []KeyValuePair { parts := strings.Split(body, "&") for _, p := range parts { split := strings.Split(p, "=") - k := split[0] - v := split[1] + + var key string + if len(split) > 0 { + key = split[0] + } + + var value string + if len(split) > 1 { + key = split[1] + } + kv := KeyValuePair{ - Key: k, - Value: v, + Key: key, + Value: value, } out = append(out, kv) } -- GitLab