1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-05 03:23:49 +08:00

style: clean code

This commit is contained in:
wdvxdr 2021-05-30 14:38:08 +08:00
parent 9f7e31766b
commit 19fdd34b7f
No known key found for this signature in database
GPG Key ID: 55FF1414A69CEBA6
2 changed files with 12 additions and 15 deletions

View File

@ -2,7 +2,6 @@ package coolq
import ( import (
"encoding/hex" "encoding/hex"
"fmt"
"io/ioutil" "io/ioutil"
"path" "path"
"strconv" "strconv"
@ -41,7 +40,6 @@ func (bot *CQBot) privateMessageEvent(c *client.QQClient, m *message.PrivateMess
bot.oneWayMsgCache.Store(m.Sender.Uin, "") bot.oneWayMsgCache.Store(m.Sender.Uin, "")
} }
id := m.Id id := m.Id
fmt.Println(m)
if bot.db != nil { if bot.db != nil {
id = bot.InsertPrivateMessage(m) id = bot.InsertPrivateMessage(m)
} }

View File

@ -122,22 +122,21 @@ func checkAuth(ctx httpCtx, token string) int {
auth := ctx.headerAuth auth := ctx.headerAuth
if auth == "" { if auth == "" {
auth = ctx.query.Get("access_token") auth = ctx.query.Get("access_token")
switch {
case auth == "":
return http.StatusUnauthorized
case auth != token:
return http.StatusForbidden
}
} else { } else {
auth := strings.SplitN(auth, " ", 2) authN := strings.SplitN(auth, " ", 2)
switch { if len(authN) == 2 {
case len(auth) != 2 || auth[1] == "": auth = authN[1]
return http.StatusUnauthorized
case auth[1] != token:
return http.StatusForbidden
} }
} }
return http.StatusOK
switch {
case auth == "":
return http.StatusUnauthorized
case auth != token:
return http.StatusForbidden
default:
return http.StatusOK
}
} }
// RunHTTPServerAndClients 启动HTTP服务器与HTTP上报客户端 // RunHTTPServerAndClients 启动HTTP服务器与HTTP上报客户端