From 7cf1d4ade80735271f8dc9586140b1602938903c Mon Sep 17 00:00:00 2001 From: lyx0 <66651385+lyx0@users.noreply.github.com> Date: Wed, 14 Feb 2024 21:57:58 +0100 Subject: [PATCH] check if userid response actually contains elements in slice --- pkg/ivr/user.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/ivr/user.go b/pkg/ivr/user.go index 26a56fe..793583f 100644 --- a/pkg/ivr/user.go +++ b/pkg/ivr/user.go @@ -18,10 +18,11 @@ func IDByUsernameReply(username string) string { return "xd" } - defer resp.Body.Close() - responseList := make([]ivrIDByUsernameResponse, 0) - _ = json.NewDecoder(resp.Body).Decode(&responseList) + err = json.NewDecoder(resp.Body).Decode(&responseList) + if len(responseList) == 0 { + return "xd" + } reply := fmt.Sprintf("%s=%s", username, responseList[0].ID) return reply @@ -39,6 +40,9 @@ func IDByUsername(username string) string { responseList := make([]ivrIDByUsernameResponse, 0) _ = json.NewDecoder(resp.Body).Decode(&responseList) + if len(responseList) == 0 { + return "xd" + } return responseList[0].ID }