mirror of
https://github.com/google/gops.git
synced 2024-11-19 20:31:58 +02:00
minor: move some code to saveConfig() to make it more readable
Signed-off-by: Alex Lyashko <alex.lyashko@gmail.com>
This commit is contained in:
parent
f80c10051e
commit
cf6d865718
@ -94,24 +94,9 @@ func Listen(opts Options) (err error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
port := listener.Addr().(*net.TCPAddr).Port
|
||||
|
||||
gopsdir := opts.ConfigDir
|
||||
if gopsdir == "" {
|
||||
cfgDir, err := internal.ConfigDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
gopsdir = cfgDir
|
||||
}
|
||||
|
||||
err = os.MkdirAll(gopsdir, os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
portfile = filepath.Join(gopsdir, strconv.Itoa(os.Getpid()))
|
||||
err = os.WriteFile(portfile, []byte(strconv.Itoa(port)), os.ModePerm)
|
||||
err = saveConfig(opts, port)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -149,6 +134,30 @@ func listen(l net.Listener) {
|
||||
}
|
||||
}
|
||||
|
||||
func saveConfig(opts Options, port int) (err error) {
|
||||
gopsdir := opts.ConfigDir
|
||||
if gopsdir == "" {
|
||||
cfgDir, err := internal.ConfigDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
gopsdir = cfgDir
|
||||
}
|
||||
|
||||
err = os.MkdirAll(gopsdir, os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
portfile = filepath.Join(gopsdir, strconv.Itoa(os.Getpid()))
|
||||
err = os.WriteFile(portfile, []byte(strconv.Itoa(port)), os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func gracefulShutdown() {
|
||||
c := make(chan os.Signal, 1)
|
||||
gosignal.Notify(c, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
|
||||
|
Loading…
Reference in New Issue
Block a user