✏️ 修复缓存上限控制

This commit is contained in:
Yiwen-Chan 2021-06-29 17:36:12 +08:00
parent a4e2389e69
commit 04593e2147

View File

@ -27,22 +27,22 @@ func init() {
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
go func() { go func() {
min := func(a, b int) int { min := func(a, b int) int {
if a > b { if a < b {
return a return a
} else { } else {
return b return b
} }
} }
for i := 0; i < min(10-cap(QUEUE), 2); i++ { for i := 0; i < min(cap(QUEUE)-len(QUEUE), 2); i++ {
resp, err := http.Get(API) resp, err := http.Get(API)
if err != nil { if err != nil {
ctx.SendChain(message.Text("ERROR: ", err)) ctx.SendChain(message.Text("ERROR: ", err))
} }
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
ctx.SendChain(message.Text("ERROR: code ", resp.StatusCode)) ctx.SendChain(message.Text("ERROR: code ", resp.StatusCode))
} }
data, _ := ioutil.ReadAll(resp.Body) data, _ := ioutil.ReadAll(resp.Body)
resp.Body.Close()
json := gjson.ParseBytes(data) json := gjson.ParseBytes(data)
if e := json.Get("error").Str; e != "" { if e := json.Get("error").Str; e != "" {
ctx.SendChain(message.Text("ERROR: ", e)) ctx.SendChain(message.Text("ERROR: ", e))