mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 03:23:49 +08:00
http post timeout setting supported. close #77
This commit is contained in:
parent
cdbf903361
commit
a075f41a51
@ -43,6 +43,7 @@ type GoCQHttpConfig struct {
|
|||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
Host string `json:"host"`
|
Host string `json:"host"`
|
||||||
Port uint16 `json:"port"`
|
Port uint16 `json:"port"`
|
||||||
|
Timeout int32 `json:"timeout"`
|
||||||
PostUrls map[string]string `json:"post_urls"`
|
PostUrls map[string]string `json:"post_urls"`
|
||||||
PostMessageFormat string `json:"post_message_format"`
|
PostMessageFormat string `json:"post_message_format"`
|
||||||
}
|
}
|
||||||
|
2
main.go
2
main.go
@ -201,7 +201,7 @@ func main() {
|
|||||||
coolq.SetMessageFormat(conf.HttpConfig.PostMessageFormat)
|
coolq.SetMessageFormat(conf.HttpConfig.PostMessageFormat)
|
||||||
}
|
}
|
||||||
for k, v := range conf.HttpConfig.PostUrls {
|
for k, v := range conf.HttpConfig.PostUrls {
|
||||||
server.NewHttpClient().Run(k, v, b)
|
server.NewHttpClient().Run(k, v, conf.HttpConfig.Timeout, b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if conf.WSConfig != nil && conf.WSConfig.Enabled {
|
if conf.WSConfig != nil && conf.WSConfig.Enabled {
|
||||||
|
@ -24,6 +24,7 @@ type httpClient struct {
|
|||||||
bot *coolq.CQBot
|
bot *coolq.CQBot
|
||||||
secret string
|
secret string
|
||||||
addr string
|
addr string
|
||||||
|
timeout int32
|
||||||
}
|
}
|
||||||
|
|
||||||
var HttpServer = &httpServer{}
|
var HttpServer = &httpServer{}
|
||||||
@ -163,10 +164,14 @@ func NewHttpClient() *httpClient {
|
|||||||
return &httpClient{}
|
return &httpClient{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *httpClient) Run(addr, secret string, bot *coolq.CQBot) {
|
func (c *httpClient) Run(addr, secret string, timeout int32, bot *coolq.CQBot) {
|
||||||
c.bot = bot
|
c.bot = bot
|
||||||
c.secret = secret
|
c.secret = secret
|
||||||
c.addr = addr
|
c.addr = addr
|
||||||
|
c.timeout = timeout
|
||||||
|
if c.timeout < 5 {
|
||||||
|
c.timeout = 5
|
||||||
|
}
|
||||||
bot.OnEventPush(c.onBotPushEvent)
|
bot.OnEventPush(c.onBotPushEvent)
|
||||||
log.Infof("HTTP POST上报器已启动: %v", addr)
|
log.Infof("HTTP POST上报器已启动: %v", addr)
|
||||||
}
|
}
|
||||||
@ -184,7 +189,7 @@ func (c *httpClient) onBotPushEvent(m coolq.MSG) {
|
|||||||
h["X-Signature"] = "sha1=" + hex.EncodeToString(mac.Sum(nil))
|
h["X-Signature"] = "sha1=" + hex.EncodeToString(mac.Sum(nil))
|
||||||
}
|
}
|
||||||
return h
|
return h
|
||||||
}()).SetTimeout(time.Second * 5).Do()
|
}()).SetTimeout(time.Second * time.Duration(c.timeout)).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("上报Event数据到 %v 失败: %v", c.addr, err)
|
log.Warnf("上报Event数据到 %v 失败: %v", c.addr, err)
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user