-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
52 lines (44 loc) · 1.13 KB
/
types.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
package tasty
import (
"encoding/json"
"strconv"
"strings"
)
type StringToFloat32 float32
// UnmarshalJSON is the custom unmarshaler interface.
func (foe *StringToFloat32) UnmarshalJSON(data []byte) error {
if string(data) == "\"\"" {
if foe != nil {
*foe = 0
}
return nil
}
num := strings.ReplaceAll(string(data), "\"", "")
if num == "NaN" {
if foe != nil {
*foe = 0
}
return nil
}
n, err := strconv.ParseFloat(num, 64)
if err != nil {
return err
}
*foe = StringToFloat32(n)
return nil
}
// MarshalJSON is the custom marshaler interface.
func (foe StringToFloat32) MarshalJSON() ([]byte, error) {
return json.Marshal(float32(foe))
}
type Pagination struct {
PerPage int `json:"per-page"`
PageOffset int `json:"page-offset"`
ItemOffset int `json:"item-offset"`
TotalItems int `json:"total-items"`
TotalPages int `json:"total-pages"`
CurrentItemCount int `json:"current-item-count"`
PreviousLink *string `json:"previous-link"`
NextLink *string `json:"next-link"`
PagingLinkTemplate *string `json:"paging-link-template"`
}