mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-04 19:17:37 +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"`
|
||||
Host string `json:"host"`
|
||||
Port uint16 `json:"port"`
|
||||
Timeout int32 `json:"timeout"`
|
||||
PostUrls map[string]string `json:"post_urls"`
|
||||
PostMessageFormat string `json:"post_message_format"`
|
||||
}
|
||||
|
2
main.go
2
main.go
@ -201,7 +201,7 @@ func main() {
|
||||
coolq.SetMessageFormat(conf.HttpConfig.PostMessageFormat)
|
||||
}
|
||||
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 {
|
||||
|
@ -21,9 +21,10 @@ type httpServer struct {
|
||||
}
|
||||
|
||||
type httpClient struct {
|
||||
bot *coolq.CQBot
|
||||
secret string
|
||||
addr string
|
||||
bot *coolq.CQBot
|
||||
secret string
|
||||
addr string
|
||||
timeout int32
|
||||
}
|
||||
|
||||
var HttpServer = &httpServer{}
|
||||
@ -163,10 +164,14 @@ func NewHttpClient() *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.secret = secret
|
||||
c.addr = addr
|
||||
c.timeout = timeout
|
||||
if c.timeout < 5 {
|
||||
c.timeout = 5
|
||||
}
|
||||
bot.OnEventPush(c.onBotPushEvent)
|
||||
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))
|
||||
}
|
||||
return h
|
||||
}()).SetTimeout(time.Second * 5).Do()
|
||||
}()).SetTimeout(time.Second * time.Duration(c.timeout)).Do()
|
||||
if err != nil {
|
||||
log.Warnf("上报Event数据到 %v 失败: %v", c.addr, err)
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user