-
Notifications
You must be signed in to change notification settings - Fork 0
/
manga.go
47 lines (41 loc) · 991 Bytes
/
manga.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
package mangaeden
import (
"encoding/json"
"strings"
"time"
)
type Manga struct {
Image
Alias string `json:"a"`
CategoriesList []string `json:"c"`
Hits int `json:"h"`
ID string `json:"i"`
LastChapterDate time.Time `json:"ld"`
StatusCode int `json:"s"`
Title string `json:"t"`
}
func (m *Manga) UnmarshalJSON(data []byte) error {
type Alias Manga
aux := &struct {
ImageURLFragment string `json:"im"`
LastChapterDate float64 `json:"ld"`
*Alias
}{
Alias: (*Alias)(m),
}
if err := json.Unmarshal(data, &aux); err != nil {
return err
}
m.ImageURLFragment = aux.ImageURLFragment
m.LastChapterDate = time.Unix(int64(aux.LastChapterDate), 0)
return nil
}
func (m Manga) IsCompleted() bool {
return m.StatusCode == STATUS_COMPLETED
}
func (m Manga) Status() string {
return completeString(m.StatusCode)
}
func (m Manga) Categories() string {
return strings.Join(m.CategoriesList, ",")
}