-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats-json.go
43 lines (34 loc) · 840 Bytes
/
stats-json.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
package claymore
import "strings"
// Stats json
type StatsJson struct {
Id int `json:"error"`
Result []string `json:"result"`
Error string `json:"error"`
}
// Get result value by index
func (j StatsJson) getOneResult(index int) (string, bool) {
if index > (len(j.Result) - 1) {
return "", false
}
return j.Result[index], true
}
// Get result items by index
func (j StatsJson) getOneResultItems(index int) ([]string, bool) {
r, ok := j.getOneResult(index)
if !ok {
return []string{}, false
}
return strings.Split(r, ";"), true
}
// Get result items by indexes
func (j StatsJson) getResultItem(resultIndex, itemIndex int) (string, bool) {
items, ok := j.getOneResultItems(resultIndex)
if !ok {
return "", false
}
if itemIndex > (len(items) - 1) {
return "", false
}
return items[itemIndex], true
}