proxy-go/internal/utils/signal.go
wood chen 26c945a3f9 feat(metrics): enhance metrics dashboard and data handling
- Improved the metrics dashboard layout with new styles for better visual presentation, including enhanced chart and control elements.
- Added functionality for auto-refreshing metrics and exporting data to CSV, improving user interaction and data accessibility.
- Implemented persistent statistics tracking in the collector, allowing for historical data retrieval and better performance monitoring.
- Enhanced database operations with optimizations for saving metrics and cleaning up old data, ensuring efficient data management.
- Introduced performance metrics tracking, providing insights into average response times and throughput.

These changes significantly enhance the usability and functionality of the metrics dashboard, providing a more robust framework for performance monitoring and data analysis.
2024-12-05 07:08:08 +08:00

33 lines
404 B
Go

package utils
import (
"os"
"os/signal"
"sync"
"syscall"
)
func SetupCloseHandler(callback func()) {
c := make(chan os.Signal, 1)
done := make(chan bool, 1)
var once sync.Once
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
once.Do(func() {
callback()
done <- true
})
}()
go func() {
select {
case <-done:
os.Exit(0)
case <-c:
os.Exit(1)
}
}()
}