From 5db7a903d3f2dcae2b2915ea16d9612dad45c7f8 Mon Sep 17 00:00:00 2001 From: Sagleft Date: Mon, 30 May 2022 19:31:42 +0300 Subject: [PATCH] add contacts data converter --- client.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index fe9bf16..03a78da 100644 --- a/client.go +++ b/client.go @@ -256,9 +256,20 @@ func (c *UtopiaClient) GetContacts(filter string) ([]ContactData, error) { } // convert result - contactsData, isConvertable := result.([]ContactData) + contactsRaw, isConvertable := result.([]interface{}) if !isConvertable { - return nil, errors.New("failed to convert result (type " + reflect.ValueOf(result).String() + ") to contacts data") + return nil, errors.New("failed to convert result (type " + reflect.ValueOf(result).String() + + ") to empty interface array") } - return contactsData, nil + + contacts := []ContactData{} + for _, contactDataRaw := range contactsRaw { + contactData, isConvertable := contactDataRaw.(ContactData) + if !isConvertable { + return nil, errors.New("failed to convert contact data raw (type " + reflect.ValueOf(contactDataRaw).String() + + ") to contact data") + } + contacts = append(contacts, contactData) + } + return contacts, nil }