implement godoxy-agent

This commit is contained in:
yusing
2025-02-10 09:36:37 +08:00
parent ecb89f80a0
commit eaf191e350
57 changed files with 1479 additions and 467 deletions

View File

@@ -34,3 +34,15 @@ func ListFiles(dir string, maxDepth int, hideHidden ...bool) ([]string, error) {
}
return files, nil
}
// FileExists checks if a file exists.
//
// If the file does not exist, it returns false and nil,
// otherwise it returns true and any error that is not os.ErrNotExist.
func FileExists(file string) (bool, error) {
_, err := os.Stat(file)
if os.IsNotExist(err) {
return false, nil
}
return true, err
}

View File

@@ -0,0 +1,25 @@
package utils
import (
"os"
"os/signal"
"syscall"
"time"
"github.com/yusing/go-proxy/internal/logging"
"github.com/yusing/go-proxy/internal/task"
)
func WaitExit(shutdownTimeout int) {
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT)
signal.Notify(sig, syscall.SIGTERM)
signal.Notify(sig, syscall.SIGHUP)
// wait for signal
<-sig
// gracefully shutdown
logging.Info().Msg("shutting down")
_ = task.GracefulShutdown(time.Second * time.Duration(shutdownTimeout))
}