forked from hanzoai/gochimp3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
json.go
82 lines (74 loc) · 1.92 KB
/
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
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
package gochimp3
import (
"encoding/json"
"strings"
)
const (
timeFormat = "2006-01-02T15:04:05-07:00"
)
func (address *Address) MarshalJSON() ([]byte, error) {
tmp := struct {
Address
CountryCode string `json:"country_code"`
}{
Address: *address,
CountryCode: strings.ToUpper(address.CountryCode),
}
return json.Marshal(tmp)
}
func (loc *MemberLocation) MarshalJSON() ([]byte, error) {
tmp := struct {
MemberLocation
CountryCode string `json:"country_code"`
}{
MemberLocation: *loc,
CountryCode: strings.ToUpper(loc.CountryCode),
}
return json.Marshal(tmp)
}
func (store *Store) MarshalJSON() ([]byte, error) {
tmp := struct {
Store
CurrencyCode string `json:"currency_code"`
}{
Store: *store,
CurrencyCode: strings.ToUpper(store.CurrencyCode),
}
return json.Marshal(tmp)
}
func (cart *Cart) MarshalJSON() ([]byte, error) {
tmp := struct {
Cart
CurrencyCode string `json:"currency_code"`
}{
Cart: *cart,
CurrencyCode: strings.ToUpper(cart.CurrencyCode),
}
return json.Marshal(tmp)
}
func (order *Order) MarshalJSON() ([]byte, error) {
tmp := struct {
Order
CurrencyCode string `json:"currency_code"`
ProcessedAtForeign string `json:"processed_at_foreign"`
CancelledAtForeign string `json:"cancelled_at_foreign"`
UpdatedAtForeign string `json:"updated_at_foreign"`
}{
Order: *order,
CurrencyCode: strings.ToUpper(order.CurrencyCode),
ProcessedAtForeign: order.ProcessedAtForeign.Format(timeFormat),
CancelledAtForeign: order.CancelledAtForeign.Format(timeFormat),
UpdatedAtForeign: order.UpdatedAtForeign.Format(timeFormat),
}
return json.Marshal(tmp)
}
func (product *Product) MarshalJSON() ([]byte, error) {
tmp := struct {
Product
PublishedAtForeign string `json:"published_at_foreign"`
}{
Product: *product,
PublishedAtForeign: product.PublishedAtForeign.Format(timeFormat),
}
return json.Marshal(tmp)
}