-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.go
96 lines (83 loc) · 2.29 KB
/
model.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
package main
import (
"fmt"
"math/rand"
"strconv"
)
//Types of titles
type Title struct{
Native string `json:"native"`
English string `json:"english"`
}
//Title of the anime
type Titles struct{
Title Title `json:"title"`
}
//Values inside of the result key
type InResult struct{
Titles Titles `json:"anilist"`
Episode int `json:"episode"`
From float64 `json:"from"`
To float64 `json:"to"`
Video string `json:"video"`
}
//List of results from json
type AnimeResult struct {
Result []InResult `json:"result"`
}
type AnimeResultAlt struct {
Result []InResultAlt `json:"result"`
}
//Optional result with episode list
type InResultAlt struct{
Titles Titles `json:"anilist"`
Episode []int `json:"episode"`
From float64 `json:"from"`
To float64 `json:"to"`
Video string `json:"video"`
}
//Returns a map of the values in the response
func (t AnimeResult) MapOutput(idx int) map[string]string {
retMap := make(map[string]string)
retMap["title_eng"] = t.Result[idx].Titles.Title.English
retMap["title_nat"] = t.Result[idx].Titles.Title.Native
retMap["episode"] = strconv.Itoa(t.Result[idx].Episode)
retMap["from"] = fmt.Sprintf("%.2f", t.Result[idx].From/60)
retMap["to"] = fmt.Sprintf("%.2f", t.Result[idx].To/60)
retMap["video"] = t.Result[idx].Video
return retMap
}
func (t AnimeResultAlt) MapOutput(idx int) map[string]string {
retMap := make(map[string]string)
retMap["title_eng"] = t.Result[idx].Titles.Title.English
retMap["title_nat"] = t.Result[idx].Titles.Title.Native
retMap["episode"] = strconv.Itoa(t.Result[idx].Episode[0])
retMap["from"] = fmt.Sprintf("%.2f", t.Result[idx].From/60)
retMap["to"] = fmt.Sprintf("%.2f", t.Result[idx].To/60)
retMap["video"] = t.Result[idx].Video
return retMap
}
//Individual quote from
type Result struct{
Anime string `json:"anime"`
Character string `json:"character"`
Quote string `json:"quote"`
}
//List of quotes from the result
type Quotes struct{
Result []Result
}
//Returns a random quote from the character
func (t Quotes) MapOutput() map[string]string{
idx := rand.Intn(5)
retMap := t.Result[idx].MapOutput()
return retMap
}
//Returns a map from the quote
func (t Result) MapOutput() map[string]string{
retMap := make(map[string]string)
retMap["anime"]=t.Anime
retMap["character"] = t.Character
retMap["quote"] = t.Quote
return retMap
}