-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
48 lines (36 loc) · 770 Bytes
/
app.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
package app
import "context"
type Application interface {
Init(ctx context.Context) error
Run(ctx context.Context) error
Reload(ctx context.Context) error
Stop(ctx context.Context) error
}
type NamedApplication interface {
Application
Name() string
}
type TestApplication struct {
IsEnable bool
stop chan struct{}
}
func (t *TestApplication) Init(ctx context.Context) error {
return nil
}
func (t *TestApplication) Run(ctx context.Context) error {
<-t.stop
return nil
}
func (t *TestApplication) Reload(ctx context.Context) error {
if err := t.Stop(ctx); err != nil {
return err
}
if err := t.Run(ctx); err != nil {
return err
}
return nil
}
func (t *TestApplication) Stop(ctx context.Context) error {
t.stop <- struct{}{}
return nil
}