-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
47 lines (40 loc) · 1.34 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
package model
import (
"fmt"
"time"
"github.com/meshify-app/meshify/util"
)
// User structure
type User struct {
Sub string `json:"sub" bson:"sub"`
Name string `json:"name" bson:"name"`
Email string `json:"email" bson:"email"`
AccountId string `json:"accountid" bson:"accountid"`
Profile string `json:"profile" bson:"profile"`
Picture string `json:"picture" bson:"picture"`
Issuer string `json:"issuer" bson:"issuer"`
Plan string `json:"plan" bson:"plan"`
IssuedAt time.Time `json:"issuedAt" bson:"issuedAt"`
CreatedBy string `json:"createdBy" bson:"createdBy"`
Created time.Time `json:"created_at" bson:"created_at"`
UpdatedBy string `json:"updatedBy" bson:"updatedBy"`
Updated time.Time `json:"updated_at" bson:"updated_at"`
}
// IsValid check if model is valid
func (a User) IsValid() []error {
errs := make([]error, 0)
// check if the name empty
if a.Name == "" {
errs = append(errs, fmt.Errorf("name is required"))
}
if a.Email == "" {
errs = append(errs, fmt.Errorf("email is required"))
}
// email is not required, but if provided must match regex
if a.Email != "" {
if !util.RegexpEmail.MatchString(a.Email) {
errs = append(errs, fmt.Errorf("email %s is invalid", a.Email))
}
}
return errs
}