From e3f0dbc4acd0f0fc00675042dd51d687e9a8a3c6 Mon Sep 17 00:00:00 2001 From: scjtqs Date: Sat, 3 Oct 2020 17:28:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E5=85=B3=E9=97=AD=20web=20admin=E7=9B=91=E5=90=AC=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/apiAdmin.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/server/apiAdmin.go b/server/apiAdmin.go index ad83d97c..7ede3285 100644 --- a/server/apiAdmin.go +++ b/server/apiAdmin.go @@ -17,6 +17,7 @@ import ( "io/ioutil" "net/http" "os" + "os/signal" "strconv" "strings" "time" @@ -69,12 +70,21 @@ func (s *webServer) Run(addr string, cli *client.QQClient) *coolq.CQBot { s.engine.Any("/admin/:action", s.admin) go func() { - log.Infof("Admin API 服务器已启动: %v", addr) - err := s.engine.Run(addr) - if err != nil { - log.Error(err) - log.Infof("请检查端口是否被占用.") - time.Sleep(time.Second * 5) + //开启端口监听 + if s.Conf.WebUi.Enabled{ + log.Infof("Admin API 服务器已启动: %v", addr) + err := s.engine.Run(addr) + if err != nil { + log.Error(err) + log.Infof("请检查端口是否被占用.") + time.Sleep(time.Second * 5) + os.Exit(1) + } + }else{ + //关闭端口监听 + c := make(chan os.Signal, 1) + signal.Notify(c, os.Interrupt, os.Kill) + <-c os.Exit(1) } }()