Skip to content

Commit

Permalink
添加可以重置listen
Browse files Browse the repository at this point in the history
  • Loading branch information
qist committed Apr 19, 2023
1 parent 0b5e3c4 commit aab3e13
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
18 changes: 14 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,15 @@ func updateTgbotSetting(tgBotToken string, tgBotChatid int, tgBotRuntime string)
}
}

func updateSetting(port int, username string, password string) {
func updateSetting(port int, username string, password string, listen string) {
err := database.InitDB(config.GetDBPath())
if err != nil {
fmt.Println(err)
return
}

settingService := service.SettingService{}

if port > 0 {
err := settingService.SetPort(port)
if err != nil {
Expand All @@ -202,6 +202,14 @@ func updateSetting(port int, username string, password string) {
fmt.Println("set username and password success")
}
}
if listen != "" {
err := settingService.SetListen(listen)
if err != nil {
fmt.Println("set listen failed:", err)
} else {
fmt.Printf("set listen %v success", listen)
}
}
}

func main() {
Expand All @@ -221,6 +229,7 @@ func main() {

settingCmd := flag.NewFlagSet("setting", flag.ExitOnError)
var port int
var listen string
var username string
var password string
var tgbottoken string
Expand All @@ -232,6 +241,7 @@ func main() {
settingCmd.BoolVar(&reset, "reset", false, "reset all settings")
settingCmd.BoolVar(&show, "show", false, "show current settings")
settingCmd.IntVar(&port, "port", 0, "set panel port")
settingCmd.StringVar(&listen, "listen", "", "set panel listen")
settingCmd.StringVar(&username, "username", "", "set login username")
settingCmd.StringVar(&password, "password", "", "set login password")
settingCmd.StringVar(&tgbottoken, "tgbottoken", "", "set telegrame bot token")
Expand Down Expand Up @@ -282,7 +292,7 @@ func main() {
if reset {
resetSetting()
} else {
updateSetting(port, username, password)
updateSetting(port, username, password, listen)
}
if show {
showSetting(show)
Expand Down
4 changes: 4 additions & 0 deletions web/service/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ func (s *SettingService) GetListen() (string, error) {
return s.getString("webListen")
}

func (s *SettingService) SetListen(listen string) error {
return s.setString("webListen", listen)
}

func (s *SettingService) GetTgBotToken() (string, error) {
return s.getString("tgBotToken")
}
Expand Down

0 comments on commit aab3e13

Please sign in to comment.