-
Notifications
You must be signed in to change notification settings - Fork 5
/
model.go
55 lines (43 loc) · 937 Bytes
/
model.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
package tormenta
import (
"time"
"github.com/jpincas/gouuidv6"
)
type Record interface {
PreSave(DB) ([]Record, error)
PostSave()
PostGet(ctx map[string]interface{})
GetCreated() time.Time
SetID(gouuidv6.UUID)
GetID() gouuidv6.UUID
}
type Model struct {
ID gouuidv6.UUID `json:"id"`
Created time.Time `json:"created"`
LastUpdated time.Time `json:"lastUpdated"`
}
func newID() gouuidv6.UUID {
return gouuidv6.New()
}
func newModel() Model {
return Model{
ID: gouuidv6.New(),
LastUpdated: time.Now(),
}
}
func (m *Model) PreSave(db DB) ([]Record, error) {
return nil, nil
}
func (m *Model) PostSave() {}
func (m *Model) PostGet(ctx map[string]interface{}) {}
func (m *Model) SetID(id gouuidv6.UUID) {
m.ID = id
}
func (m Model) GetID() gouuidv6.UUID {
return m.ID
}
func (m *Model) GetCreated() time.Time {
createdAt := m.ID.Time()
m.Created = createdAt
return createdAt
}