forked from firdasafridi/go-indodax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_info.go
72 lines (64 loc) · 1.61 KB
/
user_info.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
package indodax
import (
"encoding/json"
"fmt"
"strconv"
"strings"
"time"
)
type respGetInfo struct {
Success int
Return *UserInfo
Message string
}
// UserInfo contains balance info, wallet address, user id, profile picture, username, and email of user.
type UserInfo struct {
Balance map[string]float64
BalanceHold map[string]float64
WalletAddress map[string]string
UserId int
ProfilePicture string
UserName string
ServerTime time.Time
Email string
}
func (UserInfo *UserInfo) UnmarshalJSON(b []byte) (err error) {
var kv map[string]interface{}
err = json.Unmarshal(b, &kv)
if err != nil {
return err
}
for k, v := range kv {
k = strings.ToLower(k)
switch k {
case fieldNameBalance:
UserInfo.Balance, err = jsonToMapStringFloat64(v.(map[string]interface{}))
case fieldNameBalanceHold:
UserInfo.BalanceHold, err = jsonToMapStringFloat64(v.(map[string]interface{}))
case fieldNameWalletAddress:
UserInfo.WalletAddress, err = jsonToMapStringString(v.(map[string]interface{}))
case fieldNameUserId:
val64, err := strconv.Atoi(v.(string))
if err != nil {
return err
}
UserInfo.UserId = val64
case fieldNameProfilePicture:
UserInfo.ProfilePicture = fmt.Sprintf("%v", v)
case fieldNameEmail:
UserInfo.Email = fmt.Sprintf("%v", v)
case fieldNameUserName:
UserInfo.UserName = fmt.Sprintf("%v", v)
case fieldNameUserServerTime:
ts, err := strconv.ParseInt(fmt.Sprintf("%.0f", v), 10, 64)
if err != nil {
return err
}
UserInfo.ServerTime = time.Unix(ts, 0)
}
if err != nil {
return err
}
}
return nil
}