-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.go
69 lines (56 loc) · 1.13 KB
/
user.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
package trakt
import (
"encoding/json"
"time"
)
type Gender string
const (
GenderMale Gender = `male`
GenderFemale Gender = `female`
)
type VipStatus struct {
Active bool
EP bool
}
type UserImages struct {
Avatar *struct {
Full string `json:"full"`
} `json:"avatar"`
}
type User struct {
baseIDs `json:"ids"`
Username string `json:"username"`
Name string `json:"name"`
Gender Gender `json:"gender"`
Age uint `json:"age"`
About string `json:"about"`
Location string `json:"location"`
JoinedAt time.Time `json:"joined_at"`
Private bool `json:"private"`
Vip *VipStatus `json:"-"`
Images *UserImages `json:"images"`
}
func (u *User) UnmarshalJSON(bytes []byte) error {
type B User
type A struct {
B
Vip bool `json:"vip"`
VipEp bool `json:"vip_ep"`
}
var a = new(A)
err := json.Unmarshal(bytes, a)
if err != nil {
return nil
}
a.B.Vip = &VipStatus{
Active: a.Vip,
EP: a.VipEp,
}
*u = User(a.B)
return nil
}
type UserIterator struct{ Iterator }
func (u *UserIterator) User() (*User, error) {
rcv := &User{}
return rcv, u.Scan(rcv)
}