Files
kubescape/main.go
Ruslan Semagin fe7dad4560 Refactor: propagate context from main to avoid redundant context creation
- 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>
2025-02-11 19:52:48 +03:00

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())
}
}