From b53256ca3fde95e834c4019b37eb230f7881713e Mon Sep 17 00:00:00 2001 From: ByteDream <63594396+ByteDream@users.noreply.github.com> Date: Sun, 29 May 2022 10:10:48 +0200 Subject: [PATCH] Use Account struct directly instead of maps --- crunchyroll.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/crunchyroll.go b/crunchyroll.go index 5ee3a97..d20dd20 100644 --- a/crunchyroll.go +++ b/crunchyroll.go @@ -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 }