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
/
character.go
122 lines (102 loc) · 3.07 KB
/
character.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
package cacher
import (
"net/http"
"github.com/rl404/go-malscraper/internal"
"github.com/rl404/go-malscraper/model"
)
// GetCharacter to get character detail information.
func (c *Cacher) GetCharacter(id int) (data *model.Character, code int, err error) {
// Get from cache.
key := internal.GetKey(internal.KeyCharacter, id)
if c.cacher.Get(key, &data) == nil {
return data, http.StatusOK, nil
}
// Parse.
data, code, err = c.api.GetCharacter(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
}
// GetCharacterArticle to get character featured article list.
func (c *Cacher) GetCharacterArticle(id int) (data []model.ArticleItem, code int, err error) {
// Get from cache.
key := internal.GetKey(internal.KeyCharacterArticle, id)
if c.cacher.Get(key, &data) == nil {
return data, http.StatusOK, nil
}
// Parse.
data, code, err = c.api.GetCharacterArticle(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
}
// GetCharacterOgraphy to get character animeography/mangaography list.
func (c *Cacher) GetCharacterOgraphy(t string, id int) (data []model.Role, code int, err error) {
// Get from cache.
key := internal.GetKey(internal.KeyCharacterOgraphy, t, id)
if c.cacher.Get(key, &data) == nil {
return data, http.StatusOK, nil
}
// Parse.
data, code, err = c.api.GetCharacterOgraphy(t, 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
}
// GetCharacterPicture to get character picture list.
func (c *Cacher) GetCharacterPicture(id int) (data []string, code int, err error) {
// Get from cache.
key := internal.GetKey(internal.KeyCharacterPicture, id)
if c.cacher.Get(key, &data) == nil {
return data, http.StatusOK, nil
}
// Parse.
data, code, err = c.api.GetCharacterPicture(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
}
// GetCharacterClub to get character club list.
func (c *Cacher) GetCharacterClub(id int) (data []model.ClubItem, code int, err error) {
// Get from cache.
key := internal.GetKey(internal.KeyCharacterClub, id)
if c.cacher.Get(key, &data) == nil {
return data, http.StatusOK, nil
}
// Parse.
data, code, err = c.api.GetCharacterClub(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
}
// GetCharacterVA to get character club list.
func (c *Cacher) GetCharacterVA(id int) (data []model.Role, code int, err error) {
// Get from cache.
key := internal.GetKey(internal.KeyCharacterVA, id)
if c.cacher.Get(key, &data) == nil {
return data, http.StatusOK, nil
}
// Parse.
data, code, err = c.api.GetCharacterVA(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
}