Skip to content

Commit

Permalink
add contacts data converter
Browse files Browse the repository at this point in the history
  • Loading branch information
Sagleft committed May 30, 2022
1 parent d74dc26 commit 5db7a90
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 5db7a90

Please sign in to comment.