-
Notifications
You must be signed in to change notification settings - Fork 7
/
default.go
71 lines (63 loc) · 1.86 KB
/
default.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
package app
import (
"context"
"time"
)
var (
// DefaultGracePeriod is the default value for the grace period.
// During normal shutdown procedures, the shutdown function will wait
// this amount of time before actually starting calling the shutdown handlers.
DefaultGracePeriod = 3 * time.Second
// DefaultShutdownTimeout is the default value for the timeout during shutdown.
DefaultShutdownTimeout = 5 * time.Second
// DefaultAdminPort is the default port the app will bind the admin HTTP interface.
DefaultAdminPort = "9000"
// This is the default app.
defaultApp *App
)
// NewDefaultApp creates and sets the default app. The default app is controlled by
// public functions in app package
func NewDefaultApp(ctx context.Context) (err error) {
defaultApp, err = New(ctx, DefaultAdminPort)
if err != nil {
return err
}
defaultApp.GracePeriod = DefaultGracePeriod
defaultApp.ShutdownTimeout = DefaultShutdownTimeout
return nil
}
// RunAndWait calls the RunAndWait of the default app
func RunAndWait(f MainLoopFunc) {
if defaultApp == nil {
panic("default app not initialized")
}
defaultApp.RunAndWait(f)
}
// Shutdown calls the Shutdown of the default app
func Shutdown(ctx context.Context) error {
if defaultApp == nil {
panic("default app not initialized")
}
return defaultApp.Shutdown(ctx)
}
// RegisterShutdownHandler calls the RegisterShutdownHandler from the default app
func RegisterShutdownHandler(sh *ShutdownHandler) {
if defaultApp == nil {
panic("default app not initialized")
}
defaultApp.RegisterShutdownHandler(sh)
}
// ReadinessProbeGoup TODO
func ReadinessProbeGoup() *ProbeGroup {
if defaultApp == nil {
panic("default app not initialized")
}
return &defaultApp.Ready
}
// HealthinessProbeGroup TODO
func HealthinessProbeGroup() *ProbeGroup {
if defaultApp == nil {
panic("default app not initialized")
}
return &defaultApp.Healthy
}