2021-03-25 08:27:59 +00:00
|
|
|
package global
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os/signal"
|
|
|
|
"sync"
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2021-04-05 17:10:03 +00:00
|
|
|
globalContext context.Context
|
|
|
|
globalContextOnce sync.Once
|
2021-03-25 08:27:59 +00:00
|
|
|
)
|
|
|
|
|
2021-05-13 12:22:03 +00:00
|
|
|
// Context returns global context with initialized INT, TERM and HUP signal
|
|
|
|
// handlers set to notify this context.
|
2021-03-25 08:27:59 +00:00
|
|
|
func Context() context.Context {
|
2021-03-30 22:46:33 +00:00
|
|
|
globalContextOnce.Do(func() {
|
2021-03-25 08:27:59 +00:00
|
|
|
globalContext, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
|
|
|
|
})
|
|
|
|
return globalContext
|
|
|
|
}
|