Use Account struct directly instead of maps

This commit is contained in:
ByteDream 2022-05-29 10:10:48 +02:00 committed by GitHub
parent acc6c63ebd
commit b53256ca3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -793,8 +793,9 @@ func (c *Crunchyroll) Account() (*Account, error) {
}
defer resp.Body.Close()
var jsonBody map[string]interface{}
if err = json.NewDecoder(resp.Body).Decode(&jsonBody); err != nil {
account := &Account{}
if err = json.NewDecoder(resp.Body).Decode(&account); err != nil {
return nil, fmt.Errorf("failed to parse 'me' response: %w", err)
}
@ -804,15 +805,9 @@ func (c *Crunchyroll) Account() (*Account, error) {
}
defer resp.Body.Close()
if err = json.NewDecoder(resp.Body).Decode(&jsonBody); err != nil {
if err = json.NewDecoder(resp.Body).Decode(&account); err != nil {
return nil, fmt.Errorf("failed to parse 'profile' response: %w", err)
}
account := &Account{}
if err := decodeMapToStruct(jsonBody, account); err != nil {
return nil, err
}
return account, nil
}