diff --git a/core/frps/handler.go b/core/frps/handler.go index 334bfa8..7c5ffdc 100644 --- a/core/frps/handler.go +++ b/core/frps/handler.go @@ -28,6 +28,9 @@ func Index(c echo.Context) error { } if c.QueryParam("status") == "enable" { viper.Set("enable.frps", !viper.Get("enable.frps").(bool)) + if err := viper.WriteConfig(); err != nil { + return err // 处理错误 + } } return c.JSON(200, "success") diff --git a/core/mymiddleware/viper.go b/core/mymiddleware/viper.go index fd567e9..8b351b0 100644 --- a/core/mymiddleware/viper.go +++ b/core/mymiddleware/viper.go @@ -78,7 +78,7 @@ func showPanelAddr() { fmt.Printf("gopanel started on https://%v%v/%v\n", ipNet.IP, viper.GetString("panel.port"), viper.GetString("panel.path")) } else if ipNet.IP.To16() != nil && ipNet.IP.IsGlobalUnicast() { // Check for IPv6 unicast addresses - fmt.Printf("gopanel started on https://%v%v/%v\n", ipNet.IP, viper.GetString("panel.port"), viper.GetString("panel.path")) + fmt.Printf("gopanel started on https://[%v]%v/%v\n", ipNet.IP, viper.GetString("panel.port"), viper.GetString("panel.path")) } } } diff --git a/core/security/handler.go b/core/security/handler.go index 692e0e4..87422cf 100644 --- a/core/security/handler.go +++ b/core/security/handler.go @@ -24,20 +24,25 @@ func Index(c echo.Context) error { if err := c.Bind(req); err != nil { return err } - viper.Set("panel.port", req.Port) + + viper.Set("panel,port", req.Port) viper.Set("panel.path", req.Path) viper.Set("panel.username", req.Username) viper.Set("panel.password", req.Password) if err := viper.WriteConfig(); err != nil { return err // 处理错误 } - c.Response().After(restart()) + if err := restart(); err != nil { + return err + } return c.JSON(200, "gopanel will take a little time to reboot") case "PUT": if err := updateBinaryIfNeeded(); err != nil { return err } - c.Response().After(restart()) + if err := restart(); err != nil { + return err + } return c.JSON(200, "success") } return echo.ErrMethodNotAllowed diff --git a/core/security/restart_linux.go b/core/security/restart_linux.go index 27db3a8..8008ad9 100644 --- a/core/security/restart_linux.go +++ b/core/security/restart_linux.go @@ -4,19 +4,23 @@ package security -func restart() func() { - return func() { - executable, err := os.Executable() - if err != nil { - return - } +import ( + "os" + "syscall" +) - // 使用 syscall.Exec 替换当前进程 - err = syscall.Exec(executable, os.Args, os.Environ()) - if err != nil { - fmt.Println("Error restarting process:", err) - os.Exit(1) - } +func restart() error { + + executable, err := os.Executable() + if err != nil { + return err + } + + // 使用 syscall.Exec 替换当前进程 + err = syscall.Exec(executable, os.Args, os.Environ()) + if err != nil { + return err } + return nil } diff --git a/core/security/restart_windows.go b/core/security/restart_windows.go index 405d5f6..9be077d 100644 --- a/core/security/restart_windows.go +++ b/core/security/restart_windows.go @@ -6,8 +6,6 @@ package security import "fmt" -func restart() func() { - return func() { - fmt.Println(123) - } +func restart() error { + return fmt.Errorf("Your operating system need manually reboot") } diff --git a/core/security/update.go b/core/security/update.go index a7b67eb..d3daa55 100644 --- a/core/security/update.go +++ b/core/security/update.go @@ -100,7 +100,7 @@ func updateBinaryIfNeeded() error { fmt.Println("Binary updated successfully.") } else { - return fmt.Errorf("local binary is up-to-date") + return fmt.Errorf("latest release date is %s. Local binary is up-to-date", latestReleaseDate.Format("2006-01-02")) } return nil