This repository has been archived by the owner on Sep 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
people.go
141 lines (118 loc) · 3.47 KB
/
people.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
130
131
132
133
134
135
136
137
138
139
140
141
package cacher
import (
"net/http"
"github.com/rl404/go-malscraper/internal"
"github.com/rl404/go-malscraper/model"
)
// GetPeople to get people detail information.
func (c *Cacher) GetPeople(id int) (data *model.People, code int, err error) {
// Get from cache.
key := internal.GetKey(internal.KeyPeople, id)
if c.cacher.Get(key, &data) == nil {
return data, http.StatusOK, nil
}
// Parse.
data, code, err = c.api.GetPeople(id)
if err != nil {
return nil, code, err
}
// Save to cache. Won't return error.
_ = c.cacher.Set(key, data)
return data, http.StatusOK, nil
}
// GetPeopleCharacter to get people anime character list.
func (c *Cacher) GetPeopleCharacter(id int) (data []model.PeopleCharacter, code int, err error) {
// Get from cache.
key := internal.GetKey(internal.KeyPeopleChar, id)
if c.cacher.Get(key, &data) == nil {
return data, http.StatusOK, nil
}
// Parse.
data, code, err = c.api.GetPeopleCharacter(id)
if err != nil {
return nil, code, err
}
// Save to cache. Won't return error.
_ = c.cacher.Set(key, data)
return data, http.StatusOK, nil
}
// GetPeopleStaff to get people anime staff list.
func (c *Cacher) GetPeopleStaff(id int) (data []model.Role, code int, err error) {
// Get from cache.
key := internal.GetKey(internal.KeyPeopleStaff, id)
if c.cacher.Get(key, &data) == nil {
return data, http.StatusOK, nil
}
// Parse.
data, code, err = c.api.GetPeopleStaff(id)
if err != nil {
return nil, code, err
}
// Save to cache. Won't return error.
_ = c.cacher.Set(key, data)
return data, http.StatusOK, nil
}
// GetPeopleManga to get people published manga list.
func (c *Cacher) GetPeopleManga(id int) (data []model.Role, code int, err error) {
// Get from cache.
key := internal.GetKey(internal.KeyPeopleManga, id)
if c.cacher.Get(key, &data) == nil {
return data, http.StatusOK, nil
}
// Parse.
data, code, err = c.api.GetPeopleManga(id)
if err != nil {
return nil, code, err
}
// Save to cache. Won't return error.
_ = c.cacher.Set(key, data)
return data, http.StatusOK, nil
}
// GetPeopleNews to get people news list.
func (c *Cacher) GetPeopleNews(id int) (data []model.NewsItem, code int, err error) {
// Get from cache.
key := internal.GetKey(internal.KeyPeopleNews, id)
if c.cacher.Get(key, &data) == nil {
return data, http.StatusOK, nil
}
// Parse.
data, code, err = c.api.GetPeopleNews(id)
if err != nil {
return nil, code, err
}
// Save to cache. Won't return error.
_ = c.cacher.Set(key, data)
return data, http.StatusOK, nil
}
// GetPeopleArticle to get people featured article list.
func (c *Cacher) GetPeopleArticle(id int) (data []model.ArticleItem, code int, err error) {
// Get from cache.
key := internal.GetKey(internal.KeyPeopleArticle, id)
if c.cacher.Get(key, &data) == nil {
return data, http.StatusOK, nil
}
// Parse.
data, code, err = c.api.GetPeopleArticle(id)
if err != nil {
return nil, code, err
}
// Save to cache. Won't return error.
_ = c.cacher.Set(key, data)
return data, http.StatusOK, nil
}
// GetPeoplePicture to get people picture list.
func (c *Cacher) GetPeoplePicture(id int) (data []string, code int, err error) {
// Get from cache.
key := internal.GetKey(internal.KeyPeoplePicture, id)
if c.cacher.Get(key, &data) == nil {
return data, http.StatusOK, nil
}
// Parse.
data, code, err = c.api.GetPeoplePicture(id)
if err != nil {
return nil, code, err
}
// Save to cache. Won't return error.
_ = c.cacher.Set(key, data)
return data, http.StatusOK, nil
}