From a7f7963f1c405bf5b3271ef48b996723050f2a3e Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Mon, 8 Jan 2024 12:04:21 -0500 Subject: [PATCH] fix: DecodeMsgpackURLArray needs to parse urls and create *url.URL --- utils/array.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/utils/array.go b/utils/array.go index 1117687..a81a068 100644 --- a/utils/array.go +++ b/utils/array.go @@ -2,6 +2,7 @@ package utils import ( "errors" + "fmt" "github.com/vmihailenco/msgpack/v5" "net/url" ) @@ -60,3 +61,32 @@ func DecodeMsgpackArray(dec *msgpack.Decoder) ([]interface{}, error) { return array, nil } +func DecodeMsgpackURLArray(dec *msgpack.Decoder) ([]*url.URL, error) { + arrayLen, err := dec.DecodeInt() + if err != nil { + return nil, err + } + + urlArray := make([]*url.URL, arrayLen) + + for i := 0; i < int(arrayLen); i++ { + item, err := dec.DecodeInterface() + if err != nil { + return nil, err + } + + // Type assert each item to *url.URL + urlItem, ok := item.(string) + if !ok { + // Handle the case where the item is not a *url.URL + return nil, fmt.Errorf("expected string, got %T", item) + } + + urlArray[i], err = url.Parse(urlItem) + if err != nil { + return nil, err + } + } + + return urlArray, nil +}