Do unmarshaling in thing struct

Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
Vartan Benohanian
2020-08-30 21:25:01 -04:00
parent e1dff15901
commit 57ee41b2cf
4 changed files with 111 additions and 68 deletions
+2 -7
View File
@@ -15,11 +15,6 @@ type UserService struct {
client *Client
}
type rootUser struct {
Kind string `json:"kind,omitempty"`
Data *User `json:"data,omitempty"`
}
// User represents a Reddit user.
type User struct {
// this is not the full ID, watch out.
@@ -83,13 +78,13 @@ func (s *UserService) Get(ctx context.Context, username string) (*User, *Respons
return nil, nil, err
}
root := new(rootUser)
root := new(thing)
resp, err := s.client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
}
return root.Data, resp, nil
return root.User(), resp, nil
}
// GetMultipleByID returns multiple users from their full IDs.