/
user.go
81 lines (75 loc) · 1.71 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
70
71
72
73
74
75
76
77
78
79
80
81
package types
import (
"fmt"
"strconv"
"time"
humanize "github.com/dustin/go-humanize"
"gopkg.in/mgo.v2/bson"
)
// User represents the gql user type.
type User struct {
Email string
Name string
Username string
Balance float64
FreeGPQuota float64
Country string
Stats struct {
Star int
Project int
Planet int
Follower int // Number of fans following me
Following int // Number of users I am following
}
MembershipState string // NA, ACTIVE, SUSPENDED, TRIAL, EXPIRED, STOPPED
Membership MembershipInfo
ModelUsage float64
Developer struct {
Status string // NA, UNDER_REVIEW, TRIAL, ACTIVE, INACTIVE, EXPIRED
}
Joined time.Time
}
// NameOrEmail gives the email if username is not set.
func (u *User) NameOrEmail() string {
ret := u.Username
if bson.IsObjectIdHex(ret) {
ret = u.Email
}
return ret
}
// UserHeaderString gives a row of string for the table header.
func UserHeaderString() []string {
return []string{
"Username/Email",
"Coins",
"GP Quota",
"Membership",
"Developership",
"Free storage",
"Star",
"Project",
"Planet",
"Fans",
"Following",
"Joined",
"Country",
}
}
// RowString gives a row of string for the table output.
func (u *User) RowString() []string {
return []string{
u.NameOrEmail(),
fmt.Sprintf("%.2f", u.Balance),
fmt.Sprintf("%.2f", u.FreeGPQuota),
u.MembershipState,
u.Developer.Status,
humanize.IBytes(uint64((u.Membership.AssetStorage - u.ModelUsage) * 1048576)),
strconv.Itoa(u.Stats.Star),
strconv.Itoa(u.Stats.Project),
strconv.Itoa(u.Stats.Planet),
strconv.Itoa(u.Stats.Follower),
strconv.Itoa(u.Stats.Following),
u.Joined.Format("2006-01-02 15:04:05"),
u.Country,
}
}