mirror of
https://github.com/kubescape/kubescape.git
synced 2026-02-14 18:09:55 +00:00
- Introduced a single context in main() to handle interrupt signals (os.Interrupt, syscall.SIGTERM). - Removed repetitive context creation in the program by reusing the propagated context. - Improved code readability and maintainability by centralizing context management. - Ensured consistent handling of graceful shutdown across the program. Signed-off-by: Ruslan Semagin <pixel.365.24@gmail.com>
29 lines
541 B
Go
29 lines
541 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
|
|
"github.com/kubescape/go-logger"
|
|
"github.com/kubescape/kubescape/v3/cmd"
|
|
)
|
|
|
|
func main() {
|
|
// Capture interrupt signal
|
|
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
|
defer stop()
|
|
|
|
// Handle interrupt signal
|
|
go func() {
|
|
<-ctx.Done()
|
|
// Perform cleanup or graceful shutdown here
|
|
logger.L().StopError("Received interrupt signal, exiting...")
|
|
}()
|
|
|
|
if err := cmd.Execute(ctx); err != nil {
|
|
logger.L().Fatal(err.Error())
|
|
}
|
|
}
|