-
Notifications
You must be signed in to change notification settings - Fork 5
/
interface.go
208 lines (159 loc) · 4.74 KB
/
interface.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package gone
import (
"reflect"
"xorm.io/xorm"
)
// Goner which is an abstraction of injectable objects: can inject other Goner, can be injected by other Goner.
type Goner interface {
goneFlag()
}
type identity interface {
GetId() GonerId
}
// GonerId Goner's id
type GonerId string
// Tomb container of Goner
type Tomb interface {
SetId(GonerId) Tomb
GetId() GonerId
GetGoner() Goner
GonerIsRevive(flags ...bool) bool
}
type SetLoggerError error
type DefaultLogger interface {
SetLogger(logger SimpleLogger) SetLoggerError
}
// Cemetery which is for burying and reviving Goner
type Cemetery interface {
//DefaultLogger
Goner
//bury(goner Goner, ids ...GonerId) Tomb
//Bury a Goner to the Cemetery
Bury(Goner, ...GonerId) Cemetery
//ReplaceBury replace the Goner in the Cemetery with a new Goner
ReplaceBury(Goner, GonerId) error
//ReviveOne Revive a Goner from the Cemetery
ReviveOne(goner any) (deps []Tomb, err error)
//ReviveAllFromTombs Revive all Goner from the Cemetery
ReviveAllFromTombs() error
//reviveOneFromTomb(tomb Tomb) (deps []Tomb, err error)
reviveDependence(tomb Tomb) (deps []Tomb, err error)
//GetTomById return the Tomb by the GonerId
GetTomById(GonerId) Tomb
//GetTomByType return the Tombs by the GonerType
GetTomByType(reflect.Type) []Tomb
}
// Priest A function which has A Cemetery parameter, and return an error. use for Burying Goner
type Priest func(cemetery Cemetery) error
// Process a function which has a Cemetery parameter, and return an error. use for hooks
type Process func(cemetery Cemetery) error
type Heaven interface {
//Install do some prepare before start
Install() Heaven
//WaitEnd make program block until heaven stop
WaitEnd() Heaven
//End send a signal to heaven to stop
End() Heaven
//Start make heaven start
Start() Heaven
Stop() Heaven
//GetHeavenStopSignal return a channel to listen the signal of heaven stop
GetHeavenStopSignal() <-chan struct{}
//BeforeStart add a hook function which will execute before start;
BeforeStart(Process) Heaven
//AfterStart add a hook function which will execute after start
AfterStart(Process) Heaven
//BeforeStop add a hook function which will execute before stop
BeforeStop(Process) Heaven
//AfterStop add a hook function which will execute after stop
AfterStop(Process) Heaven
//DefaultLogger
}
type AfterReviveError error
// Prophet A interface which has a AfterRevive method
type Prophet interface {
Goner
//AfterRevive A method which will execute after revive
// Deprecate: use `AfterRevive() error` instead
AfterRevive() AfterReviveError
}
type Prophet2 interface {
Goner
//AfterRevive A method which will execute after revive
AfterRevive() error
}
type Angel interface {
Goner
Start(Cemetery) error
Stop(Cemetery) error
}
type SuckError error
type Vampire interface {
Goner
Suck(conf string, v reflect.Value) SuckError
}
type Vampire2 interface {
Goner
Suck(conf string, v reflect.Value, field reflect.StructField) error
}
// Error normal error
type Error interface {
error
Msg() string
Code() int
}
// InnerError which has stack
type InnerError interface {
Error
Stack() []byte
}
// Logger log interface
type Logger interface {
Tracef(format string, args ...any)
Debugf(format string, args ...any)
Infof(format string, args ...any)
Printf(format string, args ...any)
Warnf(format string, args ...any)
Warningf(format string, args ...any)
Errorf(format string, args ...any)
Fatalf(format string, args ...any)
Panicf(format string, args ...any)
Trace(args ...any)
Debug(args ...any)
Info(args ...any)
Print(args ...any)
Warn(args ...any)
Warning(args ...any)
Error(args ...any)
Fatal(args ...any)
Panic(args ...any)
Traceln(args ...any)
Debugln(args ...any)
Infoln(args ...any)
Println(args ...any)
Warnln(args ...any)
Warningln(args ...any)
Errorln(args ...any)
Fatalln(args ...any)
Panicln(args ...any)
}
// Tracer Log tracking, which is used to assign a unified traceId to the same call link to facilitate log tracking.
type Tracer interface {
//SetTraceId to set `traceId` to the calling function. If traceId is an empty string, an automatic one will
//be generated. TraceId can be obtained by using the GetTraceId () method in the calling function.
SetTraceId(traceId string, fn func())
//GetTraceId Get the traceId of the current goroutine
GetTraceId() string
//Go Start a new goroutine instead of `go func`, which can pass the traceid to the new goroutine.
Go(fn func())
//Recover use for catch panic in goroutine
Recover()
//RecoverSetTraceId SetTraceId and Recover
RecoverSetTraceId(traceId string, fn func())
}
type XormEngine interface {
xorm.EngineInterface
Transaction(fn func(session xorm.Interface) error) error
Sqlx(sql string, args ...any) *xorm.Session
GetOriginEngine() *xorm.Engine
}