mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-18 14:39:49 +02:00
implement godoxy-agent
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
25
internal/utils/wait_exit.go
Normal file
25
internal/utils/wait_exit.go
Normal 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))
|
||||
}
|
||||
Reference in New Issue
Block a user