-
Notifications
You must be signed in to change notification settings - Fork 3
/
characters.go
129 lines (115 loc) · 3 KB
/
characters.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package jikan
import (
"fmt"
"net/url"
)
// CharactersBase struct
type CharactersBase struct {
MalId int `json:"mal_id"`
Url string `json:"url"`
Images Images2 `json:"images"`
Name string `json:"name"`
NameKanji string `json:"name_kanji"`
Nicknames []string `json:"nicknames"`
Favorites int `json:"favorites"`
About string `json:"about"`
}
// CharacterById struct
type CharacterById struct {
Data CharactersBase `json:"data"`
}
// GetCharacterById returns character by id
func GetCharacterById(id int) (*CharacterById, error) {
res := &CharacterById{}
err := urlToStruct(fmt.Sprintf("/characters/%d", id), res)
if err != nil {
return nil, err
}
return res, nil
}
// CharacterAnime struct
type CharacterAnime struct {
Data []struct {
Role string `json:"role"`
Anime EntryTitle3 `json:"anime"`
} `json:"data"`
}
// GetCharacterAnime returns character anime
func GetCharacterAnime(id int) (*CharacterAnime, error) {
res := &CharacterAnime{}
err := urlToStruct(fmt.Sprintf("/characters/%d/anime", id), res)
if err != nil {
return nil, err
}
return res, nil
}
// CharacterManga struct
type CharacterManga struct {
Data []struct {
Role string `json:"role"`
Manga EntryTitle3 `json:"manga"`
} `json:"data"`
}
// GetCharacterManga returns character manga
func GetCharacterManga(id int) (*CharacterManga, error) {
res := &CharacterManga{}
err := urlToStruct(fmt.Sprintf("/characters/%d/manga", id), res)
if err != nil {
return nil, err
}
return res, nil
}
// CharacterVoiceActors struct
type CharacterVoiceActors struct {
Data []struct {
Language string `json:"language"`
Person struct {
MalId int `json:"mal_id"`
Url string `json:"url"`
Images struct {
Jpg struct {
ImageUrl string `json:"image_url"`
} `json:"jpg"`
} `json:"images"`
Name string `json:"name"`
} `json:"person"`
} `json:"data"`
}
// GetCharacterVoiceActors returns character manga
func GetCharacterVoiceActors(id int) (*CharacterVoiceActors, error) {
res := &CharacterVoiceActors{}
err := urlToStruct(fmt.Sprintf("/characters/%d/voices", id), res)
if err != nil {
return nil, err
}
return res, nil
}
type CharacterPictures struct {
Data []struct {
ImageUrl string `json:"image_url"`
LargeImageUrl string `json:"large_image_url"`
} `json:"data"`
}
// GetCharacterPictures returns character manga
func GetCharacterPictures(id int) (*CharacterPictures, error) {
res := &CharacterPictures{}
err := urlToStruct(fmt.Sprintf("/characters/%d/pictures", id), res)
if err != nil {
return nil, err
}
return res, nil
}
// CharactersSearch struct
type CharactersSearch struct {
Data []CharacterById `json:"data"`
Pagination Pagination `json:"pagination"`
}
// GetCharactersSearch returns characters search
func GetCharactersSearch(query url.Values) (*CharactersSearch, error) {
res := &CharactersSearch{}
err := urlToStruct(fmt.Sprintf("/characters?%s", query.Encode()), res)
if err != nil {
return nil, err
}
return res, nil
}