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
/
top.go
84 lines (70 loc) · 2.03 KB
/
top.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
package cacher
import (
"net/http"
"github.com/rl404/go-malscraper/internal"
"github.com/rl404/go-malscraper/model"
)
// GetTopAnime to get top anime list.
func (c *Cacher) GetTopAnime(t int, page int) (data []model.TopAnime, code int, err error) {
// Get from cache.
key := internal.GetKey(internal.KeyTopAnime, t, page)
if c.cacher.Get(key, &data) == nil {
return data, http.StatusOK, nil
}
// Parse.
data, code, err = c.api.GetTopAnime(t, page)
if err != nil {
return nil, code, err
}
// Save to cache. Won't return error.
_ = c.cacher.Set(key, data)
return data, http.StatusOK, nil
}
// GetTopManga to get top manga list.
func (c *Cacher) GetTopManga(t int, page int) (data []model.TopManga, code int, err error) {
// Get from cache.
key := internal.GetKey(internal.KeyTopManga, t, page)
if c.cacher.Get(key, &data) == nil {
return data, http.StatusOK, nil
}
// Parse.
data, code, err = c.api.GetTopManga(t, page)
if err != nil {
return nil, code, err
}
// Save to cache. Won't return error.
_ = c.cacher.Set(key, data)
return data, http.StatusOK, nil
}
// GetTopCharacter to get top character list.
func (c *Cacher) GetTopCharacter(page int) (data []model.TopCharacter, code int, err error) {
// Get from cache.
key := internal.GetKey(internal.KeyTopCharacter, page)
if c.cacher.Get(key, &data) == nil {
return data, http.StatusOK, nil
}
// Parse.
data, code, err = c.api.GetTopCharacter(page)
if err != nil {
return nil, code, err
}
// Save to cache. Won't return error.
_ = c.cacher.Set(key, data)
return data, http.StatusOK, nil
}
// GetTopPeople to get top people list.
func (c *Cacher) GetTopPeople(page int) (data []model.TopPeople, code int, err error) {
// Get from cache.
key := internal.GetKey(internal.KeyTopPeople, page)
if c.cacher.Get(key, &data) == nil {
return data, http.StatusOK, nil
}
// Parse.
data, code, err = c.api.GetTopPeople(page)
if err != nil {
return nil, code, err
}
// Save to cache. Won't return error.
_ = c.cacher.Set(key, data)
return data, http.StatusOK, nil
}