Skip to content

Commit

Permalink
指定端口启动失败将启用随机端口
Browse files Browse the repository at this point in the history
  • Loading branch information
2mf8 committed Aug 5, 2023
1 parent 6aa322b commit 10fbc7d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ gmc_android-sources.jar
*.aar
*.syso
*.toml
*.token
*.token
login.json
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## session.token 登录说明

### 默认端口9000,若启动失败,将依次在9001-9020端口中选择可用的端口启动。

只支持单账号登录,如需多账号登录,请放不同文件夹内,例如

```shell
Expand Down
13 changes: 12 additions & 1 deletion pkg/gmc/gmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,18 @@ func InitGin() {
router.POST("/plugin/delete/v1", handler.DeletePlugin)
realPort, err := RunGin(router, ":"+config.Port)
if err != nil {
util.FatalError(fmt.Errorf("failed to run gin, err: %+v", err))
for i := 9001; i <= 9020; i++ {
config.Port = strconv.Itoa(i)
realPort, err := RunGin(router, ":"+config.Port)
if err != nil {
log.Warn(fmt.Errorf("failed to run gin, err: %+v", err))
continue
}
config.Port = realPort
log.Infof("端口号 %s", realPort)
log.Infof(fmt.Sprintf("浏览器打开 http://localhost:%s/ 设置机器人", realPort))
break
}
}
config.Port = realPort
log.Infof("端口号 %s", realPort)
Expand Down

0 comments on commit 10fbc7d

Please sign in to comment.