/
user.go
58 lines (52 loc) · 1.62 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
package model
import (
"go.mongodb.org/mongo-driver/bson/primitive"
"time"
)
// The User holds
type User struct {
ID primitive.ObjectID `bson:"_id" json:"id"`
Name string `bson:"name" json:"name"`
UserName string `bson:"username" json:"username"`
Email string `bson:"email" json:"email"`
Address UserAddress `bson:"address" json:"address"`
Phone string `bson:"phone" json:"phone"`
Website string `bson:"website" json:"website"`
Company UserCompany `bson:"company" json:"company"`
Created time.Time `bson:"created" json:"created"`
Updated time.Time `bson:"updated" json:"updated"`
}
// The UserAddress holds
type UserAddress struct {
Street string `bson:"street" json:"street"`
Suite string `bson:"suite" json:"suite"`
City string `bson:"city" json:"city"`
Zipcode string `bson:"zipcode" json:"zipcode"`
Geo UserAddressGeo `bson:"geo" json:"geo"`
}
// The UserAddressGeo holds
type UserAddressGeo struct {
Lat string `bson:"lat" json:"lat"`
Lng string `bson:"lng" json:"lng"`
}
// The UserCompany holds
type UserCompany struct {
Name string `bson:"name" json:"name"`
CatchPhrase string `bson:"catchPhrase" json:"catchPhrase"`
BS string `bson:"bs" json:"bs"`
}
// New is
func (u *User) New() *User {
return &User{
ID: primitive.NewObjectID(),
Name: u.Name,
UserName: u.UserName,
Email: u.Email,
Address: u.Address,
Phone: u.Phone,
Website: u.Website,
Company: u.Company,
Created: time.Now(),
Updated: time.Now(),
}
}