Initial cloud-services repo - gateway service + pkg modules
This commit is contained in:
28
pkg/utils/app/app.go
Normal file
28
pkg/utils/app/app.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"fiskerinc.com/modules/logger"
|
||||
)
|
||||
|
||||
// Setup primes application while enabling proper
|
||||
// cleanup methods
|
||||
func Setup(app string, cleanup func()) {
|
||||
logger.Info().Msgf("initializing %s", app)
|
||||
EnableGracefulShutdown(cleanup)
|
||||
}
|
||||
|
||||
// EnableGracefulShutdown catches ctrl+c interrupt
|
||||
// to allow for graceful shutdowns
|
||||
func EnableGracefulShutdown(cleanup func()) {
|
||||
c := make(chan os.Signal)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||
go func() {
|
||||
<-c
|
||||
cleanup()
|
||||
os.Exit(1)
|
||||
}()
|
||||
}
|
||||
Reference in New Issue
Block a user