From d42d8dd3951545d38b92c571eed614986abd1e65 Mon Sep 17 00:00:00 2001 From: wdvxdr Date: Wed, 23 Mar 2022 19:55:21 +0800 Subject: [PATCH] server: add uri Path to address For #1415 --- server/http.go | 11 ++++++----- server/websocket.go | 8 ++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/server/http.go b/server/http.go index a43a2408a..8bc362c9f 100644 --- a/server/http.go +++ b/server/http.go @@ -244,18 +244,19 @@ func runHTTP(bot *coolq.CQBot, node yaml.Node) { return } - network, addr := "tcp", "" + network, addr := "tcp", conf.Address s := &httpServer{accessToken: conf.AccessToken} - if conf.Address != "" { + switch { + case conf.Address != "": uri, err := url.Parse(conf.Address) if err == nil && uri.Scheme != "" { network = uri.Scheme - addr = uri.Host + addr = uri.Host + uri.Path } - } else if conf.Host != "" || conf.Port != 0 { + case conf.Host != "" || conf.Port != 0: addr = fmt.Sprintf("%s:%d", conf.Host, conf.Port) log.Warnln("HTTP 服务器使用了过时的配置格式,请更新配置文件!") - } else { + default: goto client } s.api = api.NewCaller(bot) diff --git a/server/websocket.go b/server/websocket.go index 888cd49c5..df8c9a221 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -147,10 +147,10 @@ func runWSServer(b *coolq.CQBot, node yaml.Node) { log.Warn("正向 Websocket 使用了过时的配置格式,请更新配置文件") address = fmt.Sprintf("%s:%d", conf.Host, conf.Port) } else { - addr, err := url.Parse(conf.Address) - if err == nil && addr.Scheme != "" { - network = addr.Scheme - address = addr.Host + uri, err := url.Parse(conf.Address) + if err == nil && uri.Scheme != "" { + network = uri.Scheme + address = uri.Host + uri.Path } } s := &webSocketServer{