generated from bool64/go-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.go
61 lines (48 loc) · 1.32 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
package main
import (
"errors"
)
type userStatus string
func (us userStatus) Enum() []interface{} {
return []interface{}{
"new",
"approved",
"active",
"deleted",
}
}
// A demo app that receives data from http and stores it in memory.
type User struct {
FirstName string `json:"firstName" required:"true" title:"First name" minLength:"3"`
LastName string `json:"lastName" required:"true" title:"Last name" minLength:"3"`
Locale string `json:"locale" title:"User locale" enum:"ru-RU,en-US"`
Age int `json:"age" title:"Age" minimum:"1"`
Status userStatus `json:"status" title:"Status"`
Bio string `json:"bio" title:"Bio" description:"A brief description of the person." formType:"textarea"`
Code string `json:"code" formType:"ace" title:"Code" aceMode:"ace/mode/sql" minLength:"6"`
}
func (User) Title() string {
return "User"
}
func (User) Description() string {
return "User is a sample entity."
}
type userRepo struct {
st []User
schemaName string
}
func (r *userRepo) create(u User) {
r.st = append(r.st, u)
}
func (r *userRepo) update(i int, u User) {
r.st[i-1] = u
}
func (r userRepo) list() []User {
return r.st
}
func (r userRepo) get(i int) (User, error) {
if i-1 > len(r.st) {
return User{}, errors.New("user not found")
}
return r.st[i-1], nil
}