-
Notifications
You must be signed in to change notification settings - Fork 3
/
callback_interfaces.go
82 lines (69 loc) · 2.09 KB
/
callback_interfaces.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
82
package yago
// BeforeInsert can be implemented by structs that need a before insert callback
type BeforeInsert interface {
BeforeInsert(db *DB)
}
// AfterInsert can be implemented by structs that need a after insert callback
type AfterInsert interface {
AfterInsert(db *DB)
}
// BeforeUpdate can be implemented by structs that need a before update callback
type BeforeUpdate interface {
BeforeUpdate(db *DB)
}
// AfterUpdate can be implemented by structs that need a after update callback
type AfterUpdate interface {
AfterUpdate(db *DB)
}
// BeforeDelete can be implemented by structs that need a before delete callback
type BeforeDelete interface {
BeforeDelete(db *DB)
}
// AfterDelete can be implemented by structs that need a after delete callback
type AfterDelete interface {
AfterDelete(db *DB)
}
func beforeInsertInterfaceCallback(db *DB, s MappedStruct) {
if i, ok := s.(BeforeInsert); ok {
i.BeforeInsert(db)
}
}
func afterInsertInterfaceCallback(db *DB, s MappedStruct) {
if i, ok := s.(AfterInsert); ok {
i.AfterInsert(db)
}
}
func beforeUpdateInterfaceCallback(db *DB, s MappedStruct) {
if i, ok := s.(BeforeUpdate); ok {
i.BeforeUpdate(db)
}
}
func afterUpdateInterfaceCallback(db *DB, s MappedStruct) {
if i, ok := s.(AfterUpdate); ok {
i.AfterUpdate(db)
}
}
func beforeDeleteInterfaceCallback(db *DB, s MappedStruct) {
if i, ok := s.(BeforeDelete); ok {
i.BeforeDelete(db)
}
}
func afterDeleteInterfaceCallback(db *DB, s MappedStruct) {
if i, ok := s.(AfterDelete); ok {
i.AfterDelete(db)
}
}
func init() {
DefaultCallbacks.AfterInsert.Add(
Callback("yago:interface", afterInsertInterfaceCallback))
DefaultCallbacks.BeforeInsert.Add(
Callback("yago:interface", beforeInsertInterfaceCallback))
DefaultCallbacks.AfterUpdate.Add(
Callback("yago:interface", afterUpdateInterfaceCallback))
DefaultCallbacks.BeforeUpdate.Add(
Callback("yago:interface", beforeUpdateInterfaceCallback))
DefaultCallbacks.AfterDelete.Add(
Callback("yago:interface", afterDeleteInterfaceCallback))
DefaultCallbacks.BeforeDelete.Add(
Callback("yago:interface", beforeDeleteInterfaceCallback))
}