fix: DecodeMsgpackURLArray needs to parse urls and create *url.URL

This commit is contained in:
Derrick Hammer 2024-01-08 12:04:21 -05:00
parent 17d7eda377
commit a7f7963f1c
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 30 additions and 0 deletions

View File

@ -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
}