Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
G
go-cqhttp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
go-cqhttp
Commits
0f969507
Commit
0f969507
authored
Sep 02, 2020
by
wdvxdr1123
Committed by
GitHub
Sep 02, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into master
parents
993f05bf
d309a10f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
77 additions
and
9 deletions
+77
-9
Dockerfile
Dockerfile
+1
-1
coolq/api.go
coolq/api.go
+4
-4
docs/config.md
docs/config.md
+1
-1
global/config.go
global/config.go
+4
-0
go.sum
go.sum
+18
-0
server/websocket.go
server/websocket.go
+49
-3
No files found.
Dockerfile
View file @
0f969507
FROM
golang:1.14.
2
-alpine AS builder
FROM
golang:1.14.
7
-alpine AS builder
RUN
go
env
-w
GO111MODULE
=
auto
\
&&
go
env
-w
CGO_ENABLED
=
0
\
...
...
coolq/api.go
View file @
0f969507
...
...
@@ -25,7 +25,7 @@ func (bot *CQBot) CQGetLoginInfo() MSG {
// https://cqhttp.cc/docs/4.15/#/API?id=get_friend_list-%E8%8E%B7%E5%8F%96%E5%A5%BD%E5%8F%8B%E5%88%97%E8%A1%A8
func
(
bot
*
CQBot
)
CQGetFriendList
()
MSG
{
var
fs
[]
MSG
fs
:=
make
([]
MSG
,
0
)
for
_
,
f
:=
range
bot
.
Client
.
FriendList
{
fs
=
append
(
fs
,
MSG
{
"nickname"
:
f
.
Nickname
,
...
...
@@ -38,7 +38,7 @@ func (bot *CQBot) CQGetFriendList() MSG {
// https://cqhttp.cc/docs/4.15/#/API?id=get_group_list-%E8%8E%B7%E5%8F%96%E7%BE%A4%E5%88%97%E8%A1%A8
func
(
bot
*
CQBot
)
CQGetGroupList
(
noCache
bool
)
MSG
{
var
gs
[]
MSG
gs
:=
make
([]
MSG
,
0
)
if
noCache
{
_
=
bot
.
Client
.
ReloadGroupList
()
}
...
...
@@ -73,7 +73,7 @@ func (bot *CQBot) CQGetGroupMemberList(groupId int64) MSG {
if
group
==
nil
{
return
Failed
(
100
)
}
var
members
[]
MSG
members
:=
make
([]
MSG
,
0
)
for
_
,
m
:=
range
group
.
Members
{
members
=
append
(
members
,
convertGroupMemberInfo
(
groupId
,
m
))
}
...
...
@@ -525,7 +525,7 @@ func (bot *CQBot) CQGetForwardMessage(resId string) MSG {
if
m
==
nil
{
return
Failed
(
100
)
}
var
r
[]
MSG
r
:=
make
([]
MSG
,
0
)
for
_
,
n
:=
range
m
.
Nodes
{
bot
.
checkMedia
(
n
.
Message
)
r
=
append
(
r
,
MSG
{
...
...
docs/config.md
View file @
0f969507
...
...
@@ -79,6 +79,6 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
> 解密后密码将储存在内存中,用于自动重连等功能. 所以此加密并不能防止内存读取.
> 解密密钥在使用完成后并不会留存在内存中, 所以可用相对简单的字符串作为密钥
> 注2: 分片发送为原酷Q发送长消息的老方案, 发送速度更优/兼容性更好。关闭后将优先使用新方案, 能发送更长的消息, 但发送速度更慢,在部分老客户端将无法解析.
> 注2: 分片发送为原酷Q发送长消息的老方案, 发送速度更优/兼容性更好
,但在有发言频率限制的群里,可能无法发送
。关闭后将优先使用新方案, 能发送更长的消息, 但发送速度更慢,在部分老客户端将无法解析.
> 注3:关闭心跳服务可能引起断线,请谨慎关闭
global/config.go
View file @
0f969507
...
...
@@ -2,6 +2,8 @@ package global
import
(
"encoding/json"
"os"
"strconv"
"time"
log
"github.com/sirupsen/logrus"
...
...
@@ -117,6 +119,8 @@ func Load(p string) *JsonConfig {
err
:=
json
.
Unmarshal
([]
byte
(
ReadAllText
(
p
)),
&
c
)
if
err
!=
nil
{
log
.
Warnf
(
"尝试加载配置文件 %v 时出现错误: %v"
,
p
,
err
)
log
.
Infoln
(
"原文件已备份"
)
os
.
Rename
(
p
,
p
+
".backup"
+
strconv
.
FormatInt
(
time
.
Now
()
.
Unix
(),
10
))
return
nil
}
return
&
c
...
...
go.sum
View file @
0f969507
...
...
@@ -49,6 +49,8 @@ github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0U
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/guonaihong/gout v0.1.1 h1:2i3eqQ1KUhTlj7AFeIHqVUFku5QwUhwE2wNgYTVpbxQ=
github.com/guonaihong/gout v0.1.1/go.mod h1:vXvv5Kxr70eM5wrp4F0+t9lnLWmq+YPW2GByll2f/EA=
github.com/guonaihong/gout v0.1.2 h1:TR2XCRopGgJdj231IayEoeavgbznFXzzzcZVdT/hG10=
github.com/guonaihong/gout v0.1.2/go.mod h1:vXvv5Kxr70eM5wrp4F0+t9lnLWmq+YPW2GByll2f/EA=
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869/go.mod h1:cJ6Cj7dQo+O6GJNiMx+Pa94qKj+TG8ONdKHgMNIyyag=
github.com/jonboulle/clockwork v0.2.0/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
...
...
@@ -64,6 +66,8 @@ github.com/lestrrat-go/file-rotatelogs v2.3.0+incompatible h1:4mNlp+/SvALIPFpbXV
github.com/lestrrat-go/file-rotatelogs v2.3.0+incompatible/go.mod h1:ZQnN8lSECaebrkQytbHj4xNgtg8CR7RYXnPok8e0EHA=
github.com/lestrrat-go/strftime v1.0.1 h1:o7qz5pmLzPDLyGW4lG6JvTKPUfTFXwe+vOamIYWtnVU=
github.com/lestrrat-go/strftime v1.0.1/go.mod h1:E1nN3pCbtMSu1yjSVeyuRFVm/U0xoR76fd03sz+Qz4g=
github.com/lestrrat-go/strftime v1.0.3 h1:qqOPU7y+TM8Y803I8fG9c/DyKG3xH/xkng6keC1015Q=
github.com/lestrrat-go/strftime v1.0.3/go.mod h1:E1nN3pCbtMSu1yjSVeyuRFVm/U0xoR76fd03sz+Qz4g=
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
...
...
@@ -91,10 +95,14 @@ github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816/go
github.com/tebeka/strftime v0.1.5/go.mod h1:29/OidkoWHdEKZqzyDLUyC+LmgDgdHo4WAFCDT7D/Ig=
github.com/tidwall/gjson v1.6.0 h1:9VEQWz6LLMUsUl6PueE49ir4Ka6CzLymOAZDxpFsTDc=
github.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls=
github.com/tidwall/gjson v1.6.1 h1:LRbvNuNuvAiISWg6gxLEFuCe72UKy5hDqhxW/8183ws=
github.com/tidwall/gjson v1.6.1/go.mod h1:BaHyNc5bjzYkPqgLq7mdVzeiRtULKULXLgZFKsxEHI0=
github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
...
...
@@ -109,6 +117,7 @@ github.com/xujiajun/utils v0.0.0-20190123093513-8bf096c4f53b/go.mod h1:AZd87GYJl
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189 h1:4UJw9if55Fu3HOwbfcaQlJ27p3oeJU2JZqoeT3ITJQk=
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189/go.mod h1:rIrm5geMiBhPQkdfUm8gDFi/WiHneOp1i9KjmJqc+9I=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
...
...
@@ -117,8 +126,11 @@ golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73r
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa h1:F+8P+gmewFQYRk6JoLQLwjBCTu3mcIURZfNkVweuRKA=
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA=
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
...
...
@@ -126,11 +138,15 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181221143128-b4a75ba826a6/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo=
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200828194041-157a740278f4 h1:kCCpuwSAoYJPkNc6x0xT9yTtV4oKtARo4RGBQWOfg9E=
golang.org/x/sys v0.0.0-20200828194041-157a740278f4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
...
...
@@ -163,5 +179,7 @@ gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWd
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
server/websocket.go
View file @
0f969507
...
...
@@ -123,6 +123,14 @@ func (c *websocketClient) connectEvent() {
}
return
}
handshake
:=
fmt
.
Sprintf
(
`{"meta_event_type":"lifecycle","post_type":"meta_event","self_id":%d,"sub_type":"connect","time":%d}`
,
c
.
bot
.
Client
.
Uin
,
time
.
Now
()
.
Unix
())
err
=
conn
.
WriteMessage
(
websocket
.
TextMessage
,
[]
byte
(
handshake
))
if
err
!=
nil
{
log
.
Warnf
(
"反向Websocket 握手时出现错误: %v"
,
err
)
}
log
.
Infof
(
"已连接到反向Websocket Event服务器 %v"
,
c
.
conf
.
ReverseEventUrl
)
c
.
eventConn
=
&
websocketConn
{
Conn
:
conn
}
}
...
...
@@ -146,6 +154,14 @@ func (c *websocketClient) connectUniversal() {
}
return
}
handshake
:=
fmt
.
Sprintf
(
`{"meta_event_type":"lifecycle","post_type":"meta_event","self_id":%d,"sub_type":"connect","time":%d}`
,
c
.
bot
.
Client
.
Uin
,
time
.
Now
()
.
Unix
())
err
=
conn
.
WriteMessage
(
websocket
.
TextMessage
,
[]
byte
(
handshake
))
if
err
!=
nil
{
log
.
Warnf
(
"反向Websocket 握手时出现错误: %v"
,
err
)
}
wrappedConn
:=
&
websocketConn
{
Conn
:
conn
}
go
c
.
listenApi
(
wrappedConn
,
true
)
c
.
universalConn
=
wrappedConn
...
...
@@ -206,10 +222,20 @@ func (c *websocketClient) onBotPushEvent(m coolq.MSG) {
func
(
s
*
websocketServer
)
event
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
s
.
token
!=
""
{
if
r
.
URL
.
Query
()
.
Get
(
"access_token"
)
!=
s
.
token
&&
strings
.
SplitN
(
r
.
Header
.
Get
(
"Authorization"
),
" "
,
2
)[
1
]
!=
s
.
token
{
if
auth
:=
r
.
URL
.
Query
()
.
Get
(
"access_token"
);
auth
!=
s
.
token
&&
auth
!=
""
{
log
.
Warnf
(
"已拒绝 %v 的 Websocket 请求: Token错误"
,
r
.
RemoteAddr
)
w
.
WriteHeader
(
401
)
return
}
else
if
auth
:=
strings
.
SplitN
(
r
.
Header
.
Get
(
"Authorization"
),
" "
,
2
);
len
(
auth
)
==
2
{
if
auth
[
1
]
!=
s
.
token
{
log
.
Warnf
(
"已拒绝 %v 的 Websocket 请求: Token错误"
,
r
.
RemoteAddr
)
w
.
WriteHeader
(
401
)
return
}
}
else
{
log
.
Warnf
(
"已拒绝 %v 的 Websocket 请求: 空Token或传入格式错误"
,
r
.
RemoteAddr
)
w
.
WriteHeader
(
401
)
return
}
}
c
,
err
:=
upgrader
.
Upgrade
(
w
,
r
,
nil
)
...
...
@@ -235,10 +261,20 @@ func (s *websocketServer) event(w http.ResponseWriter, r *http.Request) {
func
(
s
*
websocketServer
)
api
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
s
.
token
!=
""
{
if
r
.
URL
.
Query
()
.
Get
(
"access_token"
)
!=
s
.
token
&&
strings
.
SplitN
(
r
.
Header
.
Get
(
"Authorization"
),
" "
,
2
)[
1
]
!=
s
.
token
{
if
auth
:=
r
.
URL
.
Query
()
.
Get
(
"access_token"
);
auth
!=
s
.
token
&&
auth
!=
""
{
log
.
Warnf
(
"已拒绝 %v 的 Websocket 请求: Token错误"
,
r
.
RemoteAddr
)
w
.
WriteHeader
(
401
)
return
}
else
if
auth
:=
strings
.
SplitN
(
r
.
Header
.
Get
(
"Authorization"
),
" "
,
2
);
len
(
auth
)
==
2
{
if
auth
[
1
]
!=
s
.
token
{
log
.
Warnf
(
"已拒绝 %v 的 Websocket 请求: Token错误"
,
r
.
RemoteAddr
)
w
.
WriteHeader
(
401
)
return
}
}
else
{
log
.
Warnf
(
"已拒绝 %v 的 Websocket 请求: 空Token或传入格式错误"
,
r
.
RemoteAddr
)
w
.
WriteHeader
(
401
)
return
}
}
c
,
err
:=
upgrader
.
Upgrade
(
w
,
r
,
nil
)
...
...
@@ -253,10 +289,20 @@ func (s *websocketServer) api(w http.ResponseWriter, r *http.Request) {
func
(
s
*
websocketServer
)
any
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
s
.
token
!=
""
{
if
r
.
URL
.
Query
()
.
Get
(
"access_token"
)
!=
s
.
token
&&
strings
.
SplitN
(
r
.
Header
.
Get
(
"Authorization"
),
" "
,
2
)[
1
]
!=
s
.
token
{
if
auth
:=
r
.
URL
.
Query
()
.
Get
(
"access_token"
);
auth
!=
s
.
token
&&
auth
!=
""
{
log
.
Warnf
(
"已拒绝 %v 的 Websocket 请求: Token错误"
,
r
.
RemoteAddr
)
w
.
WriteHeader
(
401
)
return
}
else
if
auth
:=
strings
.
SplitN
(
r
.
Header
.
Get
(
"Authorization"
),
" "
,
2
);
len
(
auth
)
==
2
{
if
auth
[
1
]
!=
s
.
token
{
log
.
Warnf
(
"已拒绝 %v 的 Websocket 请求: Token错误"
,
r
.
RemoteAddr
)
w
.
WriteHeader
(
401
)
return
}
}
else
{
log
.
Warnf
(
"已拒绝 %v 的 Websocket 请求: 空Token或传入格式错误"
,
r
.
RemoteAddr
)
w
.
WriteHeader
(
401
)
return
}
}
c
,
err
:=
upgrader
.
Upgrade
(
w
,
r
,
nil
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment