-
Notifications
You must be signed in to change notification settings - Fork 3
/
genres.go
42 lines (33 loc) · 912 Bytes
/
genres.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package rawg
import (
"context"
"fmt"
)
// GetGenres returns a list of video game genres
func (api *Client) GetGenres(ctx context.Context, page int, pageSize int, ordering string) ([]*Genre, int, error) {
path := "/genres"
data := map[string]interface{}{
"page": fmt.Sprint(page),
"page_size": fmt.Sprint(pageSize),
}
if ordering != "" {
data["ordering"] = ordering
}
var response struct {
Results []*Genre `json:"results"`
Count int `json:"count"`
}
if err := api.get(ctx, path, data, &response); err != nil {
return nil, 0, err
}
return response.Results, response.Count, nil
}
// GetGenre returns details of the genre
func (api *Client) GetGenre(ctx context.Context, id int) (*GenreDetailed, error) {
path := fmt.Sprintf("/genres/%d", id)
var genre GenreDetailed
if err := api.get(ctx, path, nil, &genre); err != nil {
return nil, err
}
return &genre, nil
}