diff --git a/LICENSE b/LICENSE index a662e45..be70b0f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,11 +1,13 @@ -木兰宽松许可证 +Copyright 2019 link1st -Copyright (c) [2019] [link1st] -[gowebsocket] is licensed under the Mulan PSL v1. -You can use this software according to the terms and conditions of the Mulan PSL v1. -You may obtain a copy of Mulan PSL v1 at: - http://license.coscl.org.cn/MulanPSL -THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR -PURPOSE. -See the Mulan PSL v1 for more details. \ No newline at end of file +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3277ed3 --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +.PHONY: run +run: + go run main.go diff --git a/README.md b/README.md index 02a751a..5e32c2c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,12 @@ # 基于websocket单台机器支持百万连接分布式聊天(IM)系统 - - +[![PkgGoDev](https://pkg.go.dev/badge/github.com/link1st/gowebsocket)](https://pkg.go.dev/github.com/link1st/gowebsocket/v2) +[![Release](https://img.shields.io/github/v/release/link1st/gowebsocket)](https://github.com/link1st/gowebsocket/releases) +[![Go Report Card](https://goreportcard.com/badge/github.com/link1st/gowebsocket/v2)](https://goreportcard.com/report/github.com/link1st/gowebsocket/v2) +[![OpenIssue](https://img.shields.io/github/issues/link1st/gowebsocket)](https://github.com/link1st/gowebsocket/issues) +[![ClosedIssue](https://img.shields.io/github/issues-closed/link1st/gowebsocket)](https://github.com/link1st/gowebsocket/issues?q=is%3Aissue+is%3Aclosed) +![Stars](https://img.shields.io/github/stars/link1st/gowebsocket) +![Forks](https://img.shields.io/github/forks/link1st/gowebsocket) +[![Stargazers over time](https://starchart.cc/link1st/gowebsocket.svg?variant=adaptive)](https://starchart.cc/link1st/gowebsocket) 本文将介绍如何实现一个基于websocket分布式聊天(IM)系统。 @@ -79,11 +85,11 @@ 使用golang实现websocket通讯,单机支持百万连接,使用gin框架、nginx负载、可以水平部署、程序内部相互通讯、使用grpc通讯协议。 - 一般项目中webSocket使用的架构图 -![网站架构图](http://img.91vh.com/img/%E7%BD%91%E7%AB%99%E6%9E%B6%E6%9E%84%E5%9B%BE.png) +![网站架构图](img/%E7%BD%91%E7%AB%99%E6%9E%B6%E6%9E%84%E5%9B%BE.png) #### 1.2 项目体验 - [项目地址 gowebsocket](https://github.com/link1st/gowebsocket) -- [IM-聊天首页](http://im.91vh.com/home/index) 或者在新的窗口打开 http://im.91vh.com/home/index +- [IM-聊天首页](http://im.20jd.com/home/index) 或者在新的窗口打开 http://im.20jd.com/home/index - 打开连接以后进入聊天界面 - 多人群聊可以同时打开两个窗口 @@ -94,15 +100,15 @@ WebSocket 协议在2008年诞生,2011年成为国际标准。所有浏览器 它的最大特点就是,服务器可以主动向客户端推送信息,客户端也可以主动向服务器发送信息,是真正的双向平等对话,属于服务器推送技术的一种。 - HTTP和WebSocket在通讯过程的比较 -![HTTP协议和WebSocket比较](http://img.91vh.com/img/HTTP%E5%8D%8F%E8%AE%AE%E5%92%8CWebSocket%E6%AF%94%E8%BE%83.png) +![HTTP协议和WebSocket比较](img/HTTP%E5%8D%8F%E8%AE%AE%E5%92%8CWebSocket%E6%AF%94%E8%BE%83.png) - HTTP和webSocket都支持配置证书,`ws://` 无证书 `wss://` 配置证书的协议标识 -![HTTP协议和WebSocket比较](http://img.91vh.com/img/HTTP%E5%8D%8F%E8%AE%AE%E5%92%8CWebSocket%E6%AF%94%E8%BE%83.jpeg) +![HTTP协议和WebSocket比较](img/HTTP%E5%8D%8F%E8%AE%AE%E5%92%8CWebSocket%E6%AF%94%E8%BE%83.jpeg) ### 2.2 webSocket的兼容性 - 浏览器的兼容性,开始支持webSocket的版本 -![浏览器开始支持webSocket的版本](http://img.91vh.com/img/%E6%B5%8F%E8%A7%88%E5%99%A8%E5%BC%80%E5%A7%8B%E6%94%AF%E6%8C%81webSocket%E7%9A%84%E7%89%88%E6%9C%AC.jpeg) +![浏览器开始支持webSocket的版本](img/%E6%B5%8F%E8%A7%88%E5%99%A8%E5%BC%80%E5%A7%8B%E6%94%AF%E6%8C%81webSocket%E7%9A%84%E7%89%88%E6%9C%AC.jpeg) - 服务端的支持 @@ -118,7 +124,7 @@ iOS 4.2及更高版本具有WebSockets支持 - 1. 从业务上出发,需要一个主动通达客户端的能力 > 目前大多数的请求都是使用HTTP,都是由客户端发起一个请求,有服务端处理,然后返回结果,不可以服务端主动向某一个客户端主动发送数据 -![服务端处理一个请求](http://img.91vh.com/img/%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%A4%84%E7%90%86%E4%B8%80%E4%B8%AA%E8%AF%B7%E6%B1%82.jpeg) +![服务端处理一个请求](img/%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%A4%84%E7%90%86%E4%B8%80%E4%B8%AA%E8%AF%B7%E6%B1%82.jpeg) - 2. 大多数场景我们需要主动通知用户,如:聊天系统、用户完成任务主动告诉用户、一些运营活动需要通知到在线的用户 - 3. 可以获取用户在线状态 - 4. 在没有长连接的时候通过客户端主动轮询获取数据 @@ -140,8 +146,8 @@ iOS 4.2及更高版本具有WebSockets支持 ``` # Request Headers Connection: Upgrade -Host: im.91vh.com -Origin: http://im.91vh.com +Host: im.20jd.com +Origin: http://im.20jd.com Pragma: no-cache Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits Sec-WebSocket-Key: I6qjdEaqYljv3+9x+GrhqA== @@ -149,7 +155,7 @@ Sec-WebSocket-Version: 13 Upgrade: websocket ``` -![浏览器 Network](http://img.91vh.com/img/%E6%B5%8F%E8%A7%88%E5%99%A8%20Network.png) +![浏览器 Network](img/%E6%B5%8F%E8%A7%88%E5%99%A8%20Network.png) - 2. 服务器响应升级协议 @@ -170,7 +176,7 @@ Upgrade: websocket - 3. 升级协议完成以后,客户端和服务器就可以相互发送数据 -![websocket接收和发送数据](http://img.91vh.com/img/websocket%E6%8E%A5%E6%94%B6%E5%92%8C%E5%8F%91%E9%80%81%E6%95%B0%E6%8D%AE.png) +![websocket接收和发送数据](img/websocket%E6%8E%A5%E6%94%B6%E5%92%8C%E5%8F%91%E9%80%81%E6%95%B0%E6%8D%AE.png) ## 3、如何实现基于webSocket的长连接系统 @@ -229,7 +235,7 @@ func wsPage(w http.ResponseWriter, req *http.Request) { #### 3.1.3 客户端连接的管理 - 当前程序有多少用户连接,还需要对用户广播的需要,这里我们就需要一个管理者(clientManager),处理这些事件: -- 记录全部的连接、登录用户的可以通过 **appId+uuid** 查到用户连接 +- 记录全部的连接、登录用户的可以通过 **appID+uuid** 查到用户连接 - 使用map存储,就涉及到多协程并发读写的问题,所以需要加读写锁 - 定义四个channel ,分别处理客户端建立连接、用户登录、断开连接、全员广播事件 @@ -238,7 +244,7 @@ func wsPage(w http.ResponseWriter, req *http.Request) { type ClientManager struct { Clients map[*Client]bool // 全部的连接 ClientsLock sync.RWMutex // 读写锁 - Users map[string]*Client // 登录的用户 // appId+uuid + Users map[string]*Client // 登录的用户 // appID+uuid UserLock sync.RWMutex // 读写锁 Register chan *Client // 连接连接处理 Login chan *login // 用户登录处理 @@ -338,7 +344,7 @@ func (c *Client) read() { - 登录发送数据示例: ``` -{"seq":"1565336219141-266129","cmd":"login","data":{"userId":"马远","appId":101}} +{"seq":"1565336219141-266129","cmd":"login","data":{"userID":"马远","appID":101}} ``` - 登录响应数据示例: ``` @@ -347,7 +353,7 @@ func (c *Client) read() { - websocket是双向的数据通讯,可以连续发送,如果发送的数据需要服务端回复,就需要一个**seq**来确定服务端的响应是回复哪一次的请求数据 - cmd 是用来确定动作,websocket没有类似于http的url,所以规定 cmd 是什么动作 - 目前的动作有:login/heartbeat 用来发送登录请求和连接保活(长时间没有数据发送的长连接容易被浏览器、移动中间商、nginx、服务端程序断开) -- 为什么需要AppId,UserId是表示用户的唯一字段,设计的时候为了做成通用性,设计AppId用来表示用户在哪个平台登录的(web、app、ios等),方便后续扩展 +- 为什么需要AppID,UserID是表示用户的唯一字段,设计的时候为了做成通用性,设计AppID用来表示用户在哪个平台登录的(web、app、ios等),方便后续扩展 - **request_model.go** 约定的请求数据格式 @@ -355,7 +361,7 @@ func (c *Client) read() { /************************ 请求数据 **************************/ // 通用请求数据格式 type Request struct { - Seq string `json:"seq"` // 消息的唯一Id + Seq string `json:"seq"` // 消息的唯一ID Cmd string `json:"cmd"` // 请求命令字 Data interface{} `json:"data,omitempty"` // 数据 json } @@ -363,13 +369,13 @@ type Request struct { // 登录请求数据 type Login struct { ServiceToken string `json:"serviceToken"` // 验证用户是否登录 - AppId uint32 `json:"appId,omitempty"` - UserId string `json:"userId,omitempty"` + AppID uint32 `json:"appID,omitempty"` + UserID string `json:"userID,omitempty"` } // 心跳请求数据 type HeartBeat struct { - UserId string `json:"userId,omitempty"` + UserID string `json:"userID,omitempty"` } ``` @@ -378,7 +384,7 @@ type HeartBeat struct { ``` /************************ 响应数据 **************************/ type Head struct { - Seq string `json:"seq"` // 消息的Id + Seq string `json:"seq"` // 消息的ID Cmd string `json:"cmd"` // 消息的cmd 动作 Response *Response `json:"response"` // 消息体 } @@ -419,7 +425,7 @@ func ClearTimeoutConnections() { for client := range clientManager.Clients { if client.IsHeartbeatTimeout(currentTime) { - fmt.Println("心跳时间超时 关闭连接", client.Addr, client.UserId, client.LoginTime, client.HeartbeatTime) + fmt.Println("心跳时间超时 关闭连接", client.Addr, client.UserID, client.LoginTime, client.HeartbeatTime) client.Socket.Close() } @@ -438,7 +444,7 @@ func ClearTimeoutConnections() { - 4. 监控用户连接、Goroutine数 十个内存溢出有九个和Goroutine有关 添加一个http的接口,可以查看系统的状态,防止Goroutine不回收 -[查看系统状态](http://im.91vh.com/system/state?isDebug=true) +[查看系统状态](http://im.20jd.com/system/state?isDebug=true) - 5. Nginx 配置不活跃的连接释放时间,防止忘记关闭的连接 @@ -475,7 +481,7 @@ ws.onclose = function(evt) { ``` 登录: -ws.send('{"seq":"2323","cmd":"login","data":{"userId":"11","appId":101}}'); +ws.send('{"seq":"2323","cmd":"login","data":{"userID":"11","appID":101}}'); 心跳: ws.send('{"seq":"2324","cmd":"heartbeat","data":{}}'); @@ -531,7 +537,7 @@ from:消息的发送者 { "type": "img", "from": "马超", - "url": "http://91vh.com/images/home_logo.png", + "url": "http://20jd.com/images/home_logo.png", "secret": "消息鉴权 secret", "size": { "width": 480, @@ -550,7 +556,7 @@ from:消息的发送者 - 支持水平部署,部署的机器之间可以相互通讯 - 项目架构图 -![网站架构图](http://img.91vh.com/img/%E7%BD%91%E7%AB%99%E6%9E%B6%E6%9E%84%E5%9B%BE.png) +![网站架构图](img/%E7%BD%91%E7%AB%99%E6%9E%B6%E6%9E%84%E5%9B%BE.png) ### 4.2 项目依赖 @@ -560,7 +566,7 @@ from:消息的发送者 ``` # 主要使用到的包 github.com/gin-gonic/gin@v1.4.0 -github.com/go-redis/redis +github.com/redis/go-redis/v9 github.com/gorilla/websocket github.com/spf13/viper google.golang.org/grpc @@ -604,7 +610,7 @@ redis: password: "" DB: 0 poolSize: 30 - minIdleConns: 30 + minIDleConns: 30 ``` - 启动项目 @@ -623,9 +629,9 @@ go run main.go - 在接口开发和接口文档使用的过程中,规范开发流程,减少沟通成本,所以约定一下接口开发流程和文档说明 - 接口地址 - 线上:http://im.91vh.com + 线上:http://im.20jd.com - 测试:http://im.91vh.com + 测试:http://im.20jd.com ###### 4.4.1.2 聊天页面 @@ -636,7 +642,7 @@ go run main.go | 参数 | 必填 | 类型 | 说明 | 示例 | | :----: | :----: | :----: | :----: | :----: | -| appId | 是 | uint32 | appId/房间Id | 101 | +| appID | 是 | uint32 | appID/房间ID | 101 | - 返回参数: 无 @@ -650,7 +656,7 @@ go run main.go | 参数 | 必填 | 类型 | 说明 | 示例 | | :----: | :----: | :----: | :----: | :----: | -| appId | 是 | uint32 | appId/房间Id | 101 | +| appID | 是 | uint32 | appID/房间ID | 101 | - 返回参数: @@ -685,8 +691,8 @@ go run main.go | 参数 | 必填 | 类型 | 说明 | 示例 | | :----: | :----: | :----: | :----: | :----: | -| appId | 是 | uint32 | appId/房间Id | 101 | -| userId | 是 | string | 用户Id | 黄帝 | +| appID | 是 | uint32 | appID/房间ID | 101 | +| userID | 是 | string | 用户ID | 黄帝 | - 返回参数: @@ -696,7 +702,7 @@ go run main.go | msg | 是 | string| 错误信息 |Success | | data | 是 | array | 返回数据 | | | online | 是 | bool | 发送结果 true:在线 false:不在线 | true | -| userId | 是 | string | 用户Id | 黄帝 | +| userID | 是 | string | 用户ID | 黄帝 | - 示例: @@ -706,7 +712,7 @@ go run main.go "msg": "Success", "data": { "online": true, - "userId": "黄帝" + "userID": "黄帝" } } ``` @@ -719,8 +725,9 @@ go run main.go | 参数 | 必填 | 类型 | 说明 | 示例 | | :----: | :----: | :----: | :----: | :----: | -| appId | 是 | uint32 | appId/房间Id | 101 | -| userId | 是 | string | 用户id | 黄帝 | +| appID | 是 | uint32 | appID/房间ID | 101 | +| userID | 是 | string | 用户id | 黄帝 | +| msgID | 是 | string | 消息ID | 避免重复发送 | | message | 是 | string | 消息内容 | hello | - 返回参数: @@ -752,9 +759,9 @@ go run main.go | 参数 | 必填 | 类型 | 说明 | 示例 | | :----: | :----: | :----: | :----: | :----: | -| appId | 是 | uint32 | appId/房间Id | 101 | -| userId | 是 | string | 用户id | 黄帝 | -| msgId | 是 | string | 消息Id | 避免重复发送 | +| appID | 是 | uint32 | appID/房间ID | 101 | +| userID | 是 | string | 用户id | 黄帝 | +| msgID | 是 | string | 消息ID | 避免重复发送 | | message | 是 | string | 消息内容 | hello | - 返回参数: @@ -809,8 +816,8 @@ service AccServer { // 查询用户是否在线 message QueryUsersOnlineReq { - uint32 appId = 1; // AppID - string userId = 2; // 用户ID + uint32 appID = 1; // AppID + string userID = 2; // 用户ID } message QueryUsersOnlineRsp { @@ -822,8 +829,8 @@ message QueryUsersOnlineRsp { // 发送消息 message SendMsgReq { string seq = 1; // 序列号 - uint32 appId = 2; // appId/房间Id - string userId = 3; // 用户ID + uint32 appID = 2; // appID/房间ID + string userID = 3; // 用户ID string cms = 4; // cms 动作: msg/enter/exit string type = 5; // type 消息类型,默认是 text string msg = 6; // msg @@ -833,14 +840,14 @@ message SendMsgReq { message SendMsgRsp { uint32 retCode = 1; string errMsg = 2; - string sendMsgId = 3; + string sendMsgID = 3; } // 给这台机器的房间内所有用户发送消息 message SendMsgAllReq { string seq = 1; // 序列号 - uint32 appId = 2; // appId/房间Id - string userId = 3; // 不发送的用户ID + uint32 appID = 2; // appID/房间ID + string userID = 3; // 不发送的用户ID string cms = 4; // cms 动作: msg/enter/exit string type = 5; // type 消息类型,默认是 text string msg = 6; // msg @@ -849,18 +856,18 @@ message SendMsgAllReq { message SendMsgAllRsp { uint32 retCode = 1; string errMsg = 2; - string sendMsgId = 3; + string sendMsgID = 3; } // 获取用户列表 message GetUserListReq { - uint32 appId = 1; + uint32 appID = 1; } message GetUserListRsp { uint32 retCode = 1; string errMsg = 2; - repeated string userId = 3; + repeated string userID = 3; } ``` @@ -879,8 +886,8 @@ message GetUserListRsp { - 同时我们也可以使用Nginx的不同的负载策略(轮询、weight、ip_hash) ### 5.2 nginx配置 -- 使用域名 **im.91vh.com** 为示例,参考配置 -- 一级目录**im.91vh.com/acc** 是给webSocket使用,是用nginx stream转发功能(nginx 1.3.31 开始支持,使用Tengine配置也是相同的),转发到golang 8089 端口处理 +- 使用域名 **im.20jd.com** 为示例,参考配置 +- 一级目录**im.20jd.com/acc** 是给webSocket使用,是用nginx stream转发功能(nginx 1.3.31 开始支持,使用Tengine配置也是相同的),转发到golang 8089 端口处理 - 其它目录是给HTTP使用,转发到golang 8080 端口处理 ``` @@ -899,7 +906,7 @@ upstream go-acc server { listen 80 ; - server_name im.91vh.com; + server_name im.20jd.com; index index.html index.htm ; @@ -1074,11 +1081,11 @@ net.ipv4.tcp_wmem = 4096 4096 16777216 - 项目启动注册和用户连接时序图 -![用户连接时序图](http://img.91vh.com/img/%E7%94%A8%E6%88%B7%E8%BF%9E%E6%8E%A5%E6%97%B6%E5%BA%8F%E5%9B%BE.png) +![用户连接时序图](img/%E7%94%A8%E6%88%B7%E8%BF%9E%E6%8E%A5%E6%97%B6%E5%BA%8F%E5%9B%BE.png) - 其它系统(IM、任务)向webSocket(acc)系统连接的用户发送消息时序图 -![分布是系统随机给用户发送消息](http://img.91vh.com/img/%E5%88%86%E5%B8%83%E6%98%AF%E7%B3%BB%E7%BB%9F%E9%9A%8F%E6%9C%BA%E7%BB%99%E7%94%A8%E6%88%B7%E5%8F%91%E9%80%81%E6%B6%88%E6%81%AF.png) +![分布是系统随机给用户发送消息](img/%E5%88%86%E5%B8%83%E6%98%AF%E7%B3%BB%E7%BB%9F%E9%9A%8F%E6%9C%BA%E7%BB%99%E7%94%A8%E6%88%B7%E5%8F%91%E9%80%81%E6%B6%88%E6%81%AF.png) ### 7.3 分布式系统部署 - 用水平部署两个项目(gowebsocket和gowebsocket1)演示分部署 @@ -1092,8 +1099,8 @@ app: httpPort: 8080 webSocketPort: 8089 rpcPort: 9001 - httpUrl: im.91vh.com - webSocketUrl: im.91vh.com + httpUrl: im.20jd.com + webSocketUrl: im.20jd.com # 在启动项目 go run main.go @@ -1111,8 +1118,8 @@ app: httpPort: 8081 webSocketPort: 8090 rpcPort: 9002 - httpUrl: im.91vh.com - webSocketUrl: im.91vh.com + httpUrl: im.20jd.com + webSocketUrl: im.20jd.com # 在启动第二个项目 go run main.go @@ -1163,7 +1170,7 @@ upstream go-acc - http接口,获取登录、连接数量 完成 - http接口,发送push、查询有多少人在线 完成 - grpc 程序内部通讯,发送消息 完成 -- appIds 一个用户在多个平台登录 +- appIDs 一个用户在多个平台登录 - 界面,把所有在线的人拉倒一个群里面,发送消息 完成 - ~~单聊~~、群聊 完成 - 实现分布式,水平扩张 完成 @@ -1216,7 +1223,7 @@ github 搜:link1st 查看项目 gowebsocket - 也可以添加我的微信(申请信息填写:公司、姓名,我好备注下),直接反馈给我

- 添加link1st的微信 + 添加link1st的微信

### 赞助商 @@ -1225,6 +1232,6 @@ github 搜:link1st 查看项目 gowebsocket

- +

diff --git a/common/error_code.go b/common/error_code.go index 10e01c0..9fa1f26 100644 --- a/common/error_code.go +++ b/common/error_code.go @@ -1,17 +1,11 @@ -/** -* Created by GoLand. -* User: link1st -* Date: 2019年07月25日 -* Time: 12:11 - */ - +// Package common 通用函数 package common const ( OK = 200 // Success NotLoggedIn = 1000 // 未登录 ParameterIllegal = 1001 // 参数不合法 - UnauthorizedUserId = 1002 // 非法的用户Id + UnauthorizedUserID = 1002 // 非法的用户 ID Unauthorized = 1003 // 未授权 ServerError = 1004 // 系统错误 NotData = 1005 // 没有数据 @@ -22,14 +16,14 @@ const ( RoutingNotExist = 1010 // 路由不存在 ) -// 根据错误码 获取错误信息 +// GetErrorMessage 根据错误码 获取错误信息 func GetErrorMessage(code uint32, message string) string { var codeMessage string codeMap := map[uint32]string{ OK: "Success", NotLoggedIn: "未登录", ParameterIllegal: "参数不合法", - UnauthorizedUserId: "非法的用户Id", + UnauthorizedUserID: "非法的用户ID", Unauthorized: "未授权", NotData: "没有数据", ServerError: "系统错误", diff --git a/common/rsp_common.go b/common/rsp_common.go index 4809ca0..2fd123e 100644 --- a/common/rsp_common.go +++ b/common/rsp_common.go @@ -1,30 +1,23 @@ -/** -* Created by GoLand. -* User: link1st -* Date: 2019年07月25日 -* Time: 12:11 - */ - +// Package common 通用函数 package common -type JsonResult struct { +// JSONResult json 返回结构体 +type JSONResult struct { Code uint32 `json:"code"` Msg string `json:"msg"` Data interface{} `json:"data"` } -func Response(code uint32, message string, data interface{}) JsonResult { - +// Response 响应数据结构 +func Response(code uint32, message string, data interface{}) JSONResult { message = GetErrorMessage(code, message) jsonMap := grantMap(code, message, data) - return jsonMap } // 按照接口格式生成原数据数组 -func grantMap(code uint32, message string, data interface{}) JsonResult { - - jsonMap := JsonResult{ +func grantMap(code uint32, message string, data interface{}) JSONResult { + jsonMap := JSONResult{ Code: code, Msg: message, Data: data, diff --git a/controllers/base_controller.go b/controllers/base_controller.go index b241d4f..c115ce5 100644 --- a/controllers/base_controller.go +++ b/controllers/base_controller.go @@ -1,36 +1,34 @@ -/** -* Created by GoLand. -* User: link1st -* Date: 2019年07月25日 -* Time: 12:11 - */ - +// Package controllers 控制器 package controllers import ( - "github.com/gin-gonic/gin" - "gowebsocket/common" "net/http" + + "github.com/gin-gonic/gin" + + "github.com/link1st/gowebsocket/v2/common" ) type BaseController struct { gin.Context } -// 获取全部请求解析到map +// Response 获取全部请求解析到map func Response(c *gin.Context, code uint32, msg string, data map[string]interface{}) { message := common.Response(code, msg, data) - // 允许跨域 c.Writer.Header().Set("Access-Control-Allow-Origin", "*") - c.Header("Access-Control-Allow-Origin", "*") // 这是允许访问所有域 - c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE,UPDATE") // 服务器支持的所有跨域请求的方法,为了避免浏览次请求的多次'预检'请求 - c.Header("Access-Control-Allow-Headers", "Authorization, Content-Length, X-CSRF-Token, Token,session,X_Requested_With,Accept, Origin, Host, Connection, Accept-Encoding, Accept-Language,DNT, X-CustomHeader, Keep-Alive, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Pragma") - c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers,Cache-Control,Content-Language,Content-Type,Expires,Last-Modified,Pragma,FooBar") // 跨域关键设置 让浏览器可以解析 - c.Header("Access-Control-Allow-Credentials", "true") // 跨域请求是否需要带cookie信息 默认设置为true - c.Set("content-type", "application/json") // 设置返回格式是json - + c.Header("Access-Control-Allow-Origin", "*") // 这是允许访问所有域 + c.Header("Access-Control-Allow-Methods", + "POST, GET, OPTIONS, PUT, DELETE,UPDATE") // 服务器支持的所有跨域请求的方法,为了避免浏览次请求的多次'预检'请求 + c.Header("Access-Control-Allow-Headers", + "Authorization, Content-Length, X-CSRF-Token, Token,session,X_Requested_With,Accept, Origin, Host, Connection, Accept-Encoding, Accept-Language,DNT, X-CustomHeader, Keep-Alive, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Pragma") + c.Header("Access-Control-Expose-Headers", + "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers,Cache-Control,Content-Language,Content-Type,Expires,Last-Modified,Pragma,FooBar") // 跨域关键设置 让浏览器可以解析 + c.Header("Access-Control-Allow-Credentials", + "true") // 跨域请求是否需要带cookie信息 默认设置为true + c.Set("content-type", + "application/json") // 设置返回格式是json c.JSON(http.StatusOK, message) - return } diff --git a/controllers/home/home_controller.go b/controllers/home/home_controller.go index b4c8d98..b3c0c29 100644 --- a/controllers/home/home_controller.go +++ b/controllers/home/home_controller.go @@ -1,36 +1,29 @@ -/** -* Created by GoLand. -* User: link1st -* Date: 2019年07月25日 -* Time: 12:11 - */ - +// Package home 首页 package home import ( "fmt" - "github.com/gin-gonic/gin" - "github.com/spf13/viper" - "gowebsocket/servers/websocket" "net/http" "strconv" + + "github.com/gin-gonic/gin" + "github.com/spf13/viper" + + "github.com/link1st/gowebsocket/v2/servers/websocket" ) -// 聊天页面 +// Index 聊天页面 func Index(c *gin.Context) { - - appIdStr := c.Query("appId") - appIdUint64, _ := strconv.ParseInt(appIdStr, 10, 32) - appId := uint32(appIdUint64) - if !websocket.InAppIds(appId) { - appId = websocket.GetDefaultAppId() + appIDStr := c.Query("appID") + appIDUint64, _ := strconv.ParseInt(appIDStr, 10, 32) + appID := uint32(appIDUint64) + if !websocket.InAppIDs(appID) { + appID = websocket.GetDefaultAppID() } - - fmt.Println("http_request 聊天首页", appId) - + fmt.Println("http_request 聊天首页", appID) data := gin.H{ "title": "聊天首页", - "appId": appId, + "appID": appID, "httpUrl": viper.GetString("app.httpUrl"), "webSocketUrl": viper.GetString("app.webSocketUrl"), } diff --git a/controllers/systems/system_controller.go b/controllers/systems/system_controller.go index 57aa9bf..c4eb3a0 100644 --- a/controllers/systems/system_controller.go +++ b/controllers/systems/system_controller.go @@ -1,29 +1,22 @@ -/** -* Created by GoLand. -* User: link1st -* Date: 2019年07月25日 -* Time: 12:11 - */ - +// Package systems 系统查询 package systems import ( "fmt" - "github.com/gin-gonic/gin" - "gowebsocket/common" - "gowebsocket/controllers" - "gowebsocket/servers/websocket" "runtime" + + "github.com/gin-gonic/gin" + + "github.com/link1st/gowebsocket/v2/common" + "github.com/link1st/gowebsocket/v2/controllers" + "github.com/link1st/gowebsocket/v2/servers/websocket" ) -// 查询系统状态 +// Status 查询系统状态 func Status(c *gin.Context) { - isDebug := c.Query("isDebug") fmt.Println("http_request 查询系统状态", isDebug) - data := make(map[string]interface{}) - numGoroutine := runtime.NumGoroutine() numCPU := runtime.NumCPU() @@ -33,6 +26,5 @@ func Status(c *gin.Context) { // ClientManager 信息 data["managerInfo"] = websocket.GetManagerInfo(isDebug) - controllers.Response(c, common.OK, "", data) } diff --git a/controllers/user/user_controller.go b/controllers/user/user_controller.go index ae4be57..5587277 100644 --- a/controllers/user/user_controller.go +++ b/controllers/user/user_controller.go @@ -1,122 +1,94 @@ -/** -* Created by GoLand. -* User: link1st -* Date: 2019年07月25日 -* Time: 12:11 - */ - +// Package user 用户调用接口 package user import ( "fmt" - "github.com/gin-gonic/gin" - "gowebsocket/common" - "gowebsocket/controllers" - "gowebsocket/lib/cache" - "gowebsocket/models" - "gowebsocket/servers/websocket" "strconv" -) - -// 查看全部在线用户 -func List(c *gin.Context) { - appIdStr := c.Query("appId") - appIdUint64, _ := strconv.ParseInt(appIdStr, 10, 32) - appId := uint32(appIdUint64) + "github.com/gin-gonic/gin" - fmt.Println("http_request 查看全部在线用户", appId) + "github.com/link1st/gowebsocket/v2/common" + "github.com/link1st/gowebsocket/v2/controllers" + "github.com/link1st/gowebsocket/v2/lib/cache" + "github.com/link1st/gowebsocket/v2/models" + "github.com/link1st/gowebsocket/v2/servers/websocket" +) +// List 查看全部在线用户 +func List(c *gin.Context) { + appIDStr := c.Query("appID") + appIDUint64, _ := strconv.ParseInt(appIDStr, 10, 32) + appID := uint32(appIDUint64) + fmt.Println("http_request 查看全部在线用户", appID) data := make(map[string]interface{}) - - userList := websocket.UserList(appId) + userList := websocket.UserList(appID) data["userList"] = userList data["userCount"] = len(userList) - controllers.Response(c, common.OK, "", data) } -// 查看用户是否在线 +// Online 查看用户是否在线 func Online(c *gin.Context) { - - userId := c.Query("userId") - appIdStr := c.Query("appId") - appIdUint64, _ := strconv.ParseInt(appIdStr, 10, 32) - appId := uint32(appIdUint64) - - fmt.Println("http_request 查看用户是否在线", userId, appIdStr) - + userID := c.Query("userID") + appIDStr := c.Query("appID") + appIDUint64, _ := strconv.ParseInt(appIDStr, 10, 32) + appID := uint32(appIDUint64) + fmt.Println("http_request 查看用户是否在线", userID, appIDStr) data := make(map[string]interface{}) - - online := websocket.CheckUserOnline(appId, userId) - data["userId"] = userId + online := websocket.CheckUserOnline(appID, userID) + data["userID"] = userID data["online"] = online - controllers.Response(c, common.OK, "", data) } -// 给用户发送消息 +// SendMessage 给用户发送消息 func SendMessage(c *gin.Context) { // 获取参数 - appIdStr := c.PostForm("appId") - userId := c.PostForm("userId") - msgId := c.PostForm("msgId") + appIDStr := c.PostForm("appID") + userID := c.PostForm("userID") + msgID := c.PostForm("msgID") message := c.PostForm("message") - appIdUint64, _ := strconv.ParseInt(appIdStr, 10, 32) - appId := uint32(appIdUint64) - - fmt.Println("http_request 给用户发送消息", appIdStr, userId, msgId, message) + appIDUint64, _ := strconv.ParseInt(appIDStr, 10, 32) + appID := uint32(appIDUint64) + fmt.Println("http_request 给用户发送消息", appIDStr, userID, msgID, message) // TODO::进行用户权限认证,一般是客户端传入TOKEN,然后检验TOKEN是否合法,通过TOKEN解析出来用户ID - // 本项目只是演示,所以直接过去客户端传入的用户ID(userId) - + // 本项目只是演示,所以直接过去客户端传入的用户ID(userID) data := make(map[string]interface{}) - - if cache.SeqDuplicates(msgId) { - fmt.Println("给用户发送消息 重复提交:", msgId) + if cache.SeqDuplicates(msgID) { + fmt.Println("给用户发送消息 重复提交:", msgID) controllers.Response(c, common.OK, "", data) - return } - - sendResults, err := websocket.SendUserMessage(appId, userId, msgId, message) + sendResults, err := websocket.SendUserMessage(appID, userID, msgID, message) if err != nil { data["sendResultsErr"] = err.Error() } - data["sendResults"] = sendResults - controllers.Response(c, common.OK, "", data) } -// 给全员发送消息 +// SendMessageAll 给全员发送消息 func SendMessageAll(c *gin.Context) { // 获取参数 - appIdStr := c.PostForm("appId") - userId := c.PostForm("userId") - msgId := c.PostForm("msgId") + appIDStr := c.PostForm("appID") + userID := c.PostForm("userID") + msgID := c.PostForm("msgID") message := c.PostForm("message") - appIdUint64, _ := strconv.ParseInt(appIdStr, 10, 32) - appId := uint32(appIdUint64) - - fmt.Println("http_request 给全体用户发送消息", appIdStr, userId, msgId, message) - + appIDUint64, _ := strconv.ParseInt(appIDStr, 10, 32) + appID := uint32(appIDUint64) + fmt.Println("http_request 给全体用户发送消息", appIDStr, userID, msgID, message) data := make(map[string]interface{}) - if cache.SeqDuplicates(msgId) { - fmt.Println("给用户发送消息 重复提交:", msgId) + if cache.SeqDuplicates(msgID) { + fmt.Println("给用户发送消息 重复提交:", msgID) controllers.Response(c, common.OK, "", data) - return } - - sendResults, err := websocket.SendUserMessageAll(appId, userId, msgId, models.MessageCmdMsg, message) + sendResults, err := websocket.SendUserMessageAll(appID, userID, msgID, models.MessageCmdMsg, message) if err != nil { data["sendResultsErr"] = err.Error() - } - data["sendResults"] = sendResults - controllers.Response(c, common.OK, "", data) } diff --git a/go.mod b/go.mod index 7a26dbc..ef45186 100644 --- a/go.mod +++ b/go.mod @@ -1,29 +1,55 @@ -module gowebsocket +module github.com/link1st/gowebsocket/v2 -go 1.14 +go 1.23.0 + +toolchain go1.24.0 require ( - github.com/fsnotify/fsnotify v1.4.8-0.20190312181446-1485a34d5d57 // indirect - github.com/gin-gonic/gin v1.7.2 - github.com/go-playground/validator/v10 v10.8.0 // indirect - github.com/go-redis/redis v0.0.0-20190719092155-6bc7daa5b1e8 - github.com/golang/protobuf v1.5.2 + github.com/gin-gonic/gin v1.9.1 + github.com/golang/protobuf v1.5.3 github.com/gorilla/websocket v1.4.2 + github.com/redis/go-redis/v9 v9.0.3 + github.com/spf13/viper v1.4.1-0.20190728125013-1b33e8258e07 + google.golang.org/grpc v1.56.3 + google.golang.org/protobuf v1.33.0 +) + +require ( + github.com/bytedance/sonic v1.9.1 // indirect + github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect + github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect + github.com/fsnotify/fsnotify v1.4.8-0.20190312181446-1485a34d5d57 // indirect + github.com/gabriel-vasile/mimetype v1.4.2 // indirect + github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect + github.com/go-playground/validator/v10 v10.14.0 // indirect + github.com/goccy/go-json v0.10.2 // indirect github.com/hashicorp/hcl v1.0.1-0.20190611123218-cf7d376da96d // indirect - github.com/json-iterator/go v1.1.11 // indirect - github.com/mattn/go-isatty v0.0.13 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/klauspost/cpuid/v2 v2.2.4 // indirect + github.com/leodido/go-urn v1.2.4 // indirect + github.com/magiconair/properties v1.8.1 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mitchellh/mapstructure v1.1.2 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/modern-go/reflect2 v1.0.1 // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml v1.4.1-0.20190725070617-84da2c4a25c5 // indirect - github.com/spf13/afero v1.2.2 // indirect + github.com/pelletier/go-toml/v2 v2.0.8 // indirect + github.com/spf13/afero v1.1.2 // indirect github.com/spf13/cast v1.3.1-0.20190531093228-c01685bb8421 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.4-0.20181223182923-24fa6976df40 // indirect - github.com/spf13/viper v1.4.1-0.20190728125013-1b33e8258e07 github.com/subosito/gotenv v1.1.1 // indirect - github.com/ugorji/go v1.2.6 // indirect - golang.org/x/net v0.0.0-20220607020251-c690dde0001d // indirect - google.golang.org/genproto v0.0.0-20220607223854-30acc4cbd2aa // indirect - google.golang.org/grpc v1.47.0 + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + github.com/ugorji/go/codec v1.2.11 // indirect + golang.org/x/arch v0.3.0 // indirect + golang.org/x/crypto v0.36.0 // indirect + golang.org/x/net v0.38.0 // indirect + golang.org/x/sys v0.31.0 // indirect + golang.org/x/text v0.23.0 // indirect + google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 450a29e..b4d04e7 100644 --- a/go.sum +++ b/go.sum @@ -1,24 +1,26 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= -github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/bsm/ginkgo/v2 v2.7.0 h1:ItPMPH90RbmZJt5GtkcNvIRuGEdwlBItdNVoyzaNQao= +github.com/bsm/ginkgo/v2 v2.7.0/go.mod h1:AiKlXPm7ItEHNc/2+OkrNG4E0ITzojb9/xWzvQ9XZ9w= +github.com/bsm/gomega v1.26.0 h1:LhQm+AFcgV2M0WyKroMASzAzCAJVpAxQXv4SaI9a69Y= +github.com/bsm/gomega v1.26.0/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= +github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= +github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= +github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= -github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= +github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= +github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= -github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= -github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI= -github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= -github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= -github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= @@ -28,87 +30,67 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= -github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= -github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= -github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE= -github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.8-0.20190312181446-1485a34d5d57 h1:r+AdyYQnMjCqabCiXfAES7u0tbaqXlLXuZ5FT+5OEQs= github.com/fsnotify/fsnotify v1.4.8-0.20190312181446-1485a34d5d57/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= +github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= -github.com/gin-gonic/gin v1.7.2 h1:Tg03T9yM2xa8j6I3Z3oqLaQRSmKvxPd6g/2HJ6zICFA= -github.com/gin-gonic/gin v1.7.2/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY= +github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= +github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= -github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= -github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= -github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= -github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= -github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= -github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= -github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= -github.com/go-playground/validator/v10 v10.8.0 h1:1kAa0fCrnpv+QYdkdcRzrRM7AyYs5o8+jZdJCz9xj6k= -github.com/go-playground/validator/v10 v10.8.0/go.mod h1:9JhgTzTaE31GZDpH/HSvHiRJrJ3iKAgqqH0Bl/Ocjdk= -github.com/go-redis/redis v0.0.0-20190719092155-6bc7daa5b1e8 h1:+fE3DwORl28yutMsVT36NnW52u8el5F3Ye9bgXZtokc= -github.com/go-redis/redis v0.0.0-20190719092155-6bc7daa5b1e8/go.mod h1:nuQKdm6S7SnV28NJEN2ZNbKpddAM1O76Z2LMJcIxJVM= +github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= +github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= -github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/hcl v1.0.1-0.20190611123218-cf7d376da96d h1:r4iSf+UX1tNxFJZ64FsUoOfysT7TePSbRNz4/mYGUIE= github.com/hashicorp/hcl v1.0.1-0.20190611123218-cf7d376da96d/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= -github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= -github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.11 h1:uVUAXhF2To8cbw/3xN3pxj6kk7TYKs98NIrTqPlMWAQ= -github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= +github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= @@ -116,33 +98,27 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= -github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= -github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= +github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= +github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-isatty v0.0.13 h1:qdl+GuBjcsKKDco5BsxPJlId98mSWNKqYA+Co0SC1yA= -github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= -github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= -github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w= -github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo= -github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml v1.4.1-0.20190725070617-84da2c4a25c5 h1:rW9pqjOLUVvikJFWrF53GlhmZNTFtsjjNA0LD2sYLvg= github.com/pelletier/go-toml v1.4.1-0.20190725070617-84da2c4a25c5/go.mod h1:PN7xzY2wHTK0K9p34ErDQMlFxa51Fk0OUruD3k1mMwo= +github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= +github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -150,20 +126,19 @@ github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXP github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +github.com/redis/go-redis/v9 v9.0.3 h1:+7mmR26M0IvyLxGZUHxu4GiBkJkVDid0Un+j4ScYu4k= +github.com/redis/go-redis/v9 v9.0.3/go.mod h1:WqMKv5vnQbRuZstUwxQI195wHy+t4PuXDOjzMvcuQHk= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= -github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= -github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc= -github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cast v1.3.1-0.20190531093228-c01685bb8421 h1:s+WESDalIlUupImv6znWrHX6XIRXuVTBsX633p7Ymms= github.com/spf13/cast v1.3.1-0.20190531093228-c01685bb8421/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= @@ -177,152 +152,92 @@ github.com/spf13/viper v1.4.1-0.20190728125013-1b33e8258e07 h1:Bxzp40S+I62o0BB0J github.com/spf13/viper v1.4.1-0.20190728125013-1b33e8258e07/go.mod h1:LLu5zwCkRPEBY0VPcRMqh58VtcO8Lp1DgqwstU7rYlk= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= +github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/subosito/gotenv v1.1.1 h1:TWxckSF6WVKWbo2M3tMqCtWa9NFUgqM1SSynxmYONOI= github.com/subosito/gotenv v1.1.1/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= +github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= -github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= -github.com/ugorji/go v1.2.6 h1:tGiWC9HENWE2tqYycIqFTNorMmFRVhNwCpDOpWqnk8E= -github.com/ugorji/go v1.2.6/go.mod h1:anCg0y61KIhDlPZmnH+so+RQbysYVyDko0IMgJv0Nn0= -github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= -github.com/ugorji/go/codec v1.2.6 h1:7kbGefxLoDBuYXOms4yD7223OpNMMPNPZxXk5TvFcyQ= -github.com/ugorji/go/codec v1.2.6/go.mod h1:V6TCNZ4PHqoHGFZuSG1W8nrCzzdgA2DozYxWFFpvxTw= +github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= +github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= -go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= +golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 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/crypto v0.0.0-20210711020723-a769d52b0f97 h1:/UOmuWzQfxxo9UtlXMwuQU8CMgg1eZXqTRwkSQJWKOI= -golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34= +golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc= 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= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/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-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.0.0-20220607020251-c690dde0001d h1:4SFsTMi4UahlKoloni7L4eYzhFRifURQLw+yv0QDCx8= -golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8= +golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 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= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/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-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-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I= -golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= +golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= 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/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= +golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20220607223854-30acc4cbd2aa h1:u5ndLsuhUo/bFuumgRSYgK92eCf5IEAogxgNBqAjNqs= -google.golang.org/genproto v0.0.0-20220607223854-30acc4cbd2aa/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= +google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 h1:KpwkzHKEF7B9Zxg18WzOa7djJ+Ha5DzthMyZYQfEn2A= +google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1/go.mod h1:nKE/iIaLqn2bQwXBg8f1g2Ylh6r5MN5CmZvuzZCgsCU= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.21.0 h1:G+97AoqBnmZIT91cLG/EkCoK9NSelj64P8bOHHNmGn0= google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= -google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= -google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= -google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= -google.golang.org/grpc v1.47.0 h1:9n77onPX5F3qfFCqjy9dhn8PbNQsIKeVU04J9G7umt8= -google.golang.org/grpc v1.47.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/grpc v1.56.3 h1:8I4C0Yq1EjstUzUJzpcRVbuYA2mODtEmpWiQoN/b2nc= +google.golang.org/grpc v1.56.3/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= -google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= -google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= -gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 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= +rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/helper/order_helper.go b/helper/order_helper.go index c7f9953..c4ca40a 100644 --- a/helper/order_helper.go +++ b/helper/order_helper.go @@ -1,10 +1,4 @@ -/** -* Created by GoLand. -* User: link1st -* Date: 2019年08月01日 -* Time: 18:13 - */ - +// Package helper 帮助函数 package helper import ( @@ -12,10 +6,9 @@ import ( "time" ) -func GetOrderIdTime() (orderId string) { - +// GetOrderIDTime 获取订单 ID +func GetOrderIDTime() (orderID string) { currentTime := time.Now().Nanosecond() - orderId = fmt.Sprintf("%d", currentTime) - + orderID = fmt.Sprintf("%d", currentTime) return } diff --git a/helper/server_helper.go b/helper/server_helper.go index 1ef239e..6451d85 100644 --- a/helper/server_helper.go +++ b/helper/server_helper.go @@ -1,41 +1,14 @@ -/** - * Created by GoLand. - * User: link1st - * Date: 2019年07月25日 - * Time: 17:27 - */ - +// Package helper 帮助函数 package helper import ( "net" ) -// 获取服务器Ip -// func GetServerIp() (ip string) { - -// addrs, err := net.InterfaceAddrs() - -// if err != nil { -// return "" -// } - -// for _, address := range addrs { -// // 检查ip地址判断是否回环地址 -// if ipNet, ok := address.(*net.IPNet); ok && !ipNet.IP.IsLoopback() { -// if ipNet.IP.To4() != nil { -// ip = ipNet.IP.String() -// } -// } -// } - -// return -// } - -/**** 问题:我在本地多网卡机器上,运行分布式场景,此函数返回的ip有误导致rpc连接失败。 遂google结果如下: - *** 1、https://www.jianshu.com/p/301aabc06972 - *** 2、https://www.cnblogs.com/chaselogs/p/11301940.html -****/ +// GetServerIp 获取服务端 IP +// 问题:我在本地多网卡机器上,运行分布式场景,此函数返回的ip有误导致rpc连接失败。 遂google结果如下: +// 1、https://www.jianshu.com/p/301aabc06972 +// 2、https://www.cnblogs.com/chaselogs/p/11301940.html func GetServerIp() string { ip, err := externalIP() if err != nil { @@ -45,11 +18,11 @@ func GetServerIp() string { } func externalIP() (net.IP, error) { - ifaces, err := net.Interfaces() + interfaces, err := net.Interfaces() if err != nil { return nil, err } - for _, iface := range ifaces { + for _, iface := range interfaces { if iface.Flags&net.FlagUp == 0 { continue // interface down } @@ -86,6 +59,5 @@ func getIpFromAddr(addr net.Addr) net.IP { if ip == nil { return nil // not an ipv4 address } - return ip } diff --git a/img/jetbrains_logo.png b/img/jetbrains_logo.png new file mode 100644 index 0000000..9fc3717 Binary files /dev/null and b/img/jetbrains_logo.png differ diff --git "a/img/345円276円256円344円277円241円344円272円214円347円273円264円347円240円201円.jpeg" "b/img/345円276円256円344円277円241円344円272円214円347円273円264円347円240円201円.jpeg" new file mode 100644 index 0000000..d1343a4 Binary files /dev/null and "b/img/345円276円256円344円277円241円344円272円214円347円273円264円347円240円201円.jpeg" differ diff --git a/lib/cache/server_cache.go b/lib/cache/server_cache.go index 6a6256e..6ff31c8 100644 --- a/lib/cache/server_cache.go +++ b/lib/cache/server_cache.go @@ -1,18 +1,14 @@ -/** -* Created by GoLand. -* User: link1st -* Date: 2019年08月03日 -* Time: 15:23 - */ - +// Package cache 缓存 package cache import ( + "context" "encoding/json" "fmt" - "gowebsocket/lib/redislib" - "gowebsocket/models" "strconv" + + "github.com/link1st/gowebsocket/v2/lib/redislib" + "github.com/link1st/gowebsocket/v2/models" ) const ( @@ -27,75 +23,53 @@ func getServersHashKey() (key string) { return } -// 设置服务器信息 +// SetServerInfo 设置服务器信息 func SetServerInfo(server *models.Server, currentTime uint64) (err error) { key := getServersHashKey() - value := fmt.Sprintf("%d", currentTime) - redisClient := redislib.GetClient() - number, err := redisClient.Do("hSet", key, server.String(), value).Int() + number, err := redisClient.Do(context.Background(), "hSet", key, server.String(), value).Int() if err != nil { fmt.Println("SetServerInfo", key, number, err) - return } - - if number != 1 { - - return - } - - redisClient.Do("Expire", key, serversHashCacheTime) - + redisClient.Do(context.Background(), "Expire", key, serversHashCacheTime) return } -// 下线服务器信息 +// DelServerInfo 下线服务器信息 func DelServerInfo(server *models.Server) (err error) { key := getServersHashKey() redisClient := redislib.GetClient() - number, err := redisClient.Do("hDel", key, server.String()).Int() + number, err := redisClient.Do(context.Background(), "hDel", key, server.String()).Int() if err != nil { fmt.Println("DelServerInfo", key, number, err) - return } - if number != 1 { - return } - - redisClient.Do("Expire", key, serversHashCacheTime) - + redisClient.Do(context.Background(), "Expire", key, serversHashCacheTime) return } +// GetServerAll 获取所有服务器 func GetServerAll(currentTime uint64) (servers []*models.Server, err error) { - servers = make([]*models.Server, 0) key := getServersHashKey() - redisClient := redislib.GetClient() - - val, err := redisClient.Do("hGetAll", key).Result() - + val, err := redisClient.Do(context.Background(), "hGetAll", key).Result() valByte, _ := json.Marshal(val) fmt.Println("GetServerAll", key, string(valByte)) - - serverMap, err := redisClient.HGetAll(key).Result() + serverMap, err := redisClient.HGetAll(context.Background(), key).Result() if err != nil { fmt.Println("SetServerInfo", key, err) - return } - for key, value := range serverMap { valueUint64, err := strconv.ParseUint(value, 10, 64) if err != nil { fmt.Println("GetServerAll", key, err) - return nil, err } @@ -103,16 +77,12 @@ func GetServerAll(currentTime uint64) (servers []*models.Server, err error) { if valueUint64+serversHashTimeout <= currentTime { continue } - server, err := models.StringToServer(key) if err != nil { fmt.Println("GetServerAll", key, err) - return nil, err } - servers = append(servers, server) } - return } diff --git a/lib/cache/submit_cache.go b/lib/cache/submit_cache.go index 0722f4c..8c0ab84 100644 --- a/lib/cache/submit_cache.go +++ b/lib/cache/submit_cache.go @@ -1,62 +1,50 @@ -/** - * Created by GoLand. - * User: link1st - * Date: 2019-07-26 - * Time: 09:18 - */ - +// Package cache 缓存 package cache import ( + "context" "fmt" - "gowebsocket/lib/redislib" + + "github.com/link1st/gowebsocket/v2/lib/redislib" ) const ( submitAgainPrefix = "acc:submit:again:" // 数据不重复提交 ) -/********************* 查询数据是否处理过 ************************/ - -// 获取数据提交去除key +// getSubmitAgainKey 获取数据提交去除key func getSubmitAgainKey(from string, value string) (key string) { key = fmt.Sprintf("%s%s:%s", submitAgainPrefix, from, value) return } -// 重复提交 +// submitAgain 重复提交 // return true:重复提交 false:第一次提交 func submitAgain(from string, second int, value string) (isSubmitAgain bool) { // 默认重复提交 isSubmitAgain = true key := getSubmitAgainKey(from, value) - redisClient := redislib.GetClient() - number, err := redisClient.Do("setNx", key, "1").Int() + number, err := redisClient.Do(context.Background(), "setNx", key, "1").Int() if err != nil { fmt.Println("submitAgain", key, number, err) - return } - if number != 1 { - return } + // 第一次提交 isSubmitAgain = false - - redisClient.Do("Expire", key, second) - + redisClient.Do(context.Background(), "Expire", key, second) return } -// Seq 重复提交 +// SeqDuplicates Seq 重复提交 func SeqDuplicates(seq string) (result bool) { result = submitAgain("seq", 12*60*60, seq) - return } diff --git a/lib/cache/user_cache.go b/lib/cache/user_cache.go index af1e0d9..f29e99d 100644 --- a/lib/cache/user_cache.go +++ b/lib/cache/user_cache.go @@ -1,18 +1,16 @@ -/** - * Created by GoLand. - * User: link1st - * Date: 2019-07-25 - * Time: 17:28 - */ - +// Package cache 缓存 package cache import ( + "context" "encoding/json" + "errors" "fmt" - "github.com/go-redis/redis" - "gowebsocket/lib/redislib" - "gowebsocket/models" + + "github.com/link1st/gowebsocket/v2/lib/redislib" + "github.com/link1st/gowebsocket/v2/models" + + "github.com/redis/go-redis/v9" ) const ( @@ -20,63 +18,48 @@ const ( userOnlineCacheTime = 24 * 60 * 60 ) -/********************* 查询用户是否在线 ************************/ func getUserOnlineKey(userKey string) (key string) { key = fmt.Sprintf("%s%s", userOnlinePrefix, userKey) - return } +// GetUserOnlineInfo 获取用户在线信息 func GetUserOnlineInfo(userKey string) (userOnline *models.UserOnline, err error) { redisClient := redislib.GetClient() - key := getUserOnlineKey(userKey) - - data, err := redisClient.Get(key).Bytes() + data, err := redisClient.Get(context.Background(), key).Bytes() if err != nil { - if err == redis.Nil { + if errors.Is(err, redis.Nil) { fmt.Println("GetUserOnlineInfo", userKey, err) - return } - fmt.Println("GetUserOnlineInfo", userKey, err) - return } - userOnline = &models.UserOnline{} err = json.Unmarshal(data, userOnline) if err != nil { fmt.Println("获取用户在线数据 json Unmarshal", userKey, err) - return } - - fmt.Println("获取用户在线数据", userKey, "time", userOnline.LoginTime, userOnline.HeartbeatTime, "AccIp", userOnline.AccIp, userOnline.IsLogoff) - + fmt.Println("获取用户在线数据", userKey, "time", userOnline.LoginTime, userOnline.HeartbeatTime, "AccIp", + userOnline.AccIp, userOnline.IsLogoff) return } -// 设置用户在线数据 +// SetUserOnlineInfo 设置用户在线数据 func SetUserOnlineInfo(userKey string, userOnline *models.UserOnline) (err error) { - redisClient := redislib.GetClient() key := getUserOnlineKey(userKey) - valueByte, err := json.Marshal(userOnline) if err != nil { fmt.Println("设置用户在线数据 json Marshal", key, err) - return } - - _, err = redisClient.Do("setEx", key, userOnlineCacheTime, string(valueByte)).Result() + _, err = redisClient.Do(context.Background(), "setEx", key, userOnlineCacheTime, string(valueByte)).Result() if err != nil { fmt.Println("设置用户在线数据 ", key, err) - return } - return } diff --git a/lib/redislib/redis_lib.go b/lib/redislib/redis_lib.go index 1c46ee8..e8cbca5 100644 --- a/lib/redislib/redis_lib.go +++ b/lib/redislib/redis_lib.go @@ -1,15 +1,11 @@ -/** -* Created by GoLand. -* User: link1st -* Date: 2019-07-25 -* Time: 14:18 - */ - +// Package redislib redis 库 package redislib import ( + "context" "fmt" - "github.com/go-redis/redis" + + "github.com/redis/go-redis/v9" "github.com/spf13/viper" ) @@ -17,8 +13,8 @@ var ( client *redis.Client ) -func ExampleNewClient() { - +// NewClient 初始化 Redis 客户端 +func NewClient() { client = redis.NewClient(&redis.Options{ Addr: viper.GetString("redis.addr"), Password: viper.GetString("redis.password"), @@ -26,13 +22,11 @@ func ExampleNewClient() { PoolSize: viper.GetInt("redis.poolSize"), MinIdleConns: viper.GetInt("redis.minIdleConns"), }) - - pong, err := client.Ping().Result() + pong, err := client.Ping(context.Background()).Result() fmt.Println("初始化redis:", pong, err) - // Output: PONG } +// GetClient 获取客户端 func GetClient() (c *redis.Client) { - return client } diff --git a/main.go b/main.go index 862910c..f82a128 100644 --- a/main.go +++ b/main.go @@ -1,36 +1,30 @@ -/** -* Created by GoLand. -* User: link1st -* Date: 2019年07月25日 -* Time: 09:59 - */ - +// Package main 实现一个基于websocket分布式聊天(IM)系统。 package main import ( "fmt" - "github.com/gin-gonic/gin" - "github.com/spf13/viper" - "gowebsocket/lib/redislib" - "gowebsocket/routers" - "gowebsocket/servers/grpcserver" - "gowebsocket/servers/task" - "gowebsocket/servers/websocket" "io" "net/http" "os" "os/exec" "time" + + "github.com/gin-gonic/gin" + "github.com/spf13/viper" + + "github.com/link1st/gowebsocket/v2/lib/redislib" + "github.com/link1st/gowebsocket/v2/routers" + "github.com/link1st/gowebsocket/v2/servers/grpcserver" + "github.com/link1st/gowebsocket/v2/servers/task" + "github.com/link1st/gowebsocket/v2/servers/websocket" ) func main() { initConfig() - initFile() - initRedis() - router := gin.Default() + // 初始化路由 routers.Init(router) routers.WebsocketInit() @@ -40,19 +34,16 @@ func main() { // 服务注册 task.ServerInit() - go websocket.StartWebSocket() + // grpc go grpcserver.Init() - go open() - httpPort := viper.GetString("app.httpPort") - http.ListenAndServe(":"+httpPort, router) - + _ = http.ListenAndServe(":"+httpPort, router) } -// 初始化日志 +// initFile 初始化日志 func initFile() { // Disable Console Color, you don't need console color when writing the logs to file. gin.DisableConsoleColor() @@ -65,31 +56,25 @@ func initFile() { func initConfig() { viper.SetConfigName("config/app") - viper.AddConfigPath(".") // 添加搜索路径 - + viper.AddConfigPath(".") err := viper.ReadInConfig() if err != nil { panic(fmt.Errorf("Fatal error config file: %s \n", err)) } - fmt.Println("config app:", viper.Get("app")) fmt.Println("config redis:", viper.Get("redis")) } func initRedis() { - redislib.ExampleNewClient() + redislib.NewClient() } func open() { - time.Sleep(1000 * time.Millisecond) - httpUrl := viper.GetString("app.httpUrl") httpUrl = "http://" + httpUrl + "/home/index" - fmt.Println("访问页面体验:", httpUrl) - cmd := exec.Command("open", httpUrl) - cmd.Output() + _, _ = cmd.Output() } diff --git a/models/msg_model.go b/models/msg_model.go index 7188772..9b27402 100644 --- a/models/msg_model.go +++ b/models/msg_model.go @@ -1,23 +1,20 @@ -/** -* Created by GoLand. -* User: link1st -* Date: 2019年08月01日 -* Time: 10:40 - */ - +// Package models 数据模型 package models -import "gowebsocket/common" +import "github.com/link1st/gowebsocket/v2/common" const ( + // MessageTypeText 文本类型消息 MessageTypeText = "text" - - MessageCmdMsg = "msg" + // MessageCmdMsg 文本类型消息 + MessageCmdMsg = "msg" + // MessageCmdEnter 用户进入类型消息 MessageCmdEnter = "enter" - MessageCmdExit = "exit" + // MessageCmdExit 用户退出类型消息 + MessageCmdExit = "exit" ) -// 消息的定义 +// Message 消息的定义 type Message struct { Target string `json:"target"` // 目标 Type string `json:"type"` // 消息类型 text/img/ @@ -25,44 +22,39 @@ type Message struct { From string `json:"from"` // 发送者 } -func NewTestMsg(from string, Msg string) (message *Message) { - +// NewMsg 创建新的消息 +func NewMsg(from string, Msg string) (message *Message) { message = &Message{ Type: MessageTypeText, From: from, Msg: Msg, } - return } -func getTextMsgData(cmd, uuId, msgId, message string) string { - textMsg := NewTestMsg(uuId, message) - head := NewResponseHead(msgId, cmd, common.OK, "Ok", textMsg) +func getTextMsgData(cmd, uuID, msgID, message string) string { + textMsg := NewMsg(uuID, message) + head := NewResponseHead(msgID, cmd, common.OK, "Ok", textMsg) return head.String() } -// 文本消息 -func GetMsgData(uuId, msgId, cmd, message string) string { - - return getTextMsgData(cmd, uuId, msgId, message) +// GetMsgData 文本消息 +func GetMsgData(uuID, msgID, cmd, message string) string { + return getTextMsgData(cmd, uuID, msgID, message) } -// 文本消息 -func GetTextMsgData(uuId, msgId, message string) string { - - return getTextMsgData("msg", uuId, msgId, message) +// GetTextMsgData 文本消息 +func GetTextMsgData(uuID, msgID, message string) string { + return getTextMsgData("msg", uuID, msgID, message) } -// 用户进入消息 -func GetTextMsgDataEnter(uuId, msgId, message string) string { - - return getTextMsgData("enter", uuId, msgId, message) +// GetTextMsgDataEnter 用户进入消息 +func GetTextMsgDataEnter(uuID, msgID, message string) string { + return getTextMsgData("enter", uuID, msgID, message) } -// 用户退出消息 -func GetTextMsgDataExit(uuId, msgId, message string) string { - - return getTextMsgData("exit", uuId, msgId, message) +// GetTextMsgDataExit 用户退出消息 +func GetTextMsgDataExit(uuID, msgID, message string) string { + return getTextMsgData("exit", uuID, msgID, message) } diff --git a/models/request_model.go b/models/request_model.go index 7c0aea4..9670c7e 100644 --- a/models/request_model.go +++ b/models/request_model.go @@ -1,28 +1,21 @@ -/** - * Created by GoLand. - * User: link1st - * Date: 2019年07月27日 - * Time: 14:41 - */ - +// Package models 数据模型 package models -/************************ 请求数据 **************************/ -// 通用请求数据格式 +// Request 通用请求数据格式 type Request struct { - Seq string `json:"seq"` // 消息的唯一Id + Seq string `json:"seq"` // 消息的唯一ID Cmd string `json:"cmd"` // 请求命令字 Data interface{} `json:"data,omitempty"` // 数据 json } -// 登录请求数据 +// Login 登录请求数据 type Login struct { ServiceToken string `json:"serviceToken"` // 验证用户是否登录 - AppId uint32 `json:"appId,omitempty"` - UserId string `json:"userId,omitempty"` + AppID uint32 `json:"appID,omitempty"` + UserID string `json:"userID,omitempty"` } -// 心跳请求数据 +// HeartBeat 心跳请求数据 type HeartBeat struct { - UserId string `json:"userId,omitempty"` + UserID string `json:"userID,omitempty"` } diff --git a/models/response_model.go b/models/response_model.go index f508b15..02410f6 100644 --- a/models/response_model.go +++ b/models/response_model.go @@ -1,28 +1,23 @@ -/** -* Created by GoLand. -* User: link1st -* Date: 2019年08月01日 -* Time: 10:46 - */ - +// Package models 数据模型 package models import "encoding/json" -/************************ 响应数据 **************************/ +// Head 响应数据头 type Head struct { - Seq string `json:"seq"` // 消息的Id + Seq string `json:"seq"` // 消息的ID Cmd string `json:"cmd"` // 消息的cmd 动作 Response *Response `json:"response"` // 消息体 } +// Response 响应数据体 type Response struct { Code uint32 `json:"code"` CodeMsg string `json:"codeMsg"` Data interface{} `json:"data"` // 数据 json } -// push 数据结构体 +// PushMsg 数据结构体 type PushMsg struct { Seq string `json:"seq"` Uuid uint64 `json:"uuid"` @@ -30,13 +25,14 @@ type PushMsg struct { Msg string `json:"msg"` } -// 设置返回消息 +// NewResponseHead 设置返回消息 func NewResponseHead(seq string, cmd string, code uint32, codeMsg string, data interface{}) *Head { response := NewResponse(code, codeMsg, data) return &Head{Seq: seq, Cmd: cmd, Response: response} } +// String to string func (h *Head) String() (headStr string) { headBytes, _ := json.Marshal(h) headStr = string(headBytes) @@ -44,6 +40,7 @@ func (h *Head) String() (headStr string) { return } +// NewResponse 创建新的响应 func NewResponse(code uint32, codeMsg string, data interface{}) *Response { return &Response{Code: code, CodeMsg: codeMsg, Data: data} } diff --git a/models/server_model.go b/models/server_model.go index fa3ebea..5ad0e8c 100644 --- a/models/server_model.go +++ b/models/server_model.go @@ -1,10 +1,4 @@ -/** -* Created by GoLand. -* User: link1st -* Date: 2019年08月03日 -* Time: 15:38 - */ - +// Package models 数据模型 package models import ( @@ -13,37 +7,35 @@ import ( "strings" ) +// Server 服务器结构体 type Server struct { Ip string `json:"ip"` // ip Port string `json:"port"` // 端口 } +// NewServer 创建 func NewServer(ip string, port string) *Server { - return &Server{Ip: ip, Port: port} } +// String to string func (s *Server) String() (str string) { if s == nil { return } - str = fmt.Sprintf("%s:%s", s.Ip, s.Port) - return } +// StringToServer 字符串转结构体 func StringToServer(str string) (server *Server, err error) { list := strings.Split(str, ":") if len(list) != 2 { - return nil, errors.New("err") } - server = &Server{ Ip: list[0], Port: list[1], } - return } diff --git a/models/user_model.go b/models/user_model.go index 07bd441..3529ee1 100644 --- a/models/user_model.go +++ b/models/user_model.go @@ -1,10 +1,4 @@ -/** - * Created by GoLand. - * User: link1st - * Date: 2019年07月25日 - * Time: 17:36 - */ - +// Package models 数据模型 package models import ( @@ -16,12 +10,12 @@ const ( heartbeatTimeout = 3 * 60 // 用户心跳超时时间 ) -// 用户在线状态 +// UserOnline 用户在线状态 type UserOnline struct { AccIp string `json:"accIp"` // acc Ip AccPort string `json:"accPort"` // acc 端口 - AppId uint32 `json:"appId"` // appId - UserId string `json:"userId"` // 用户Id + AppID uint32 `json:"appID"` // appID + UserID string `json:"userID"` // 用户ID ClientIp string `json:"clientIp"` // 客户端Ip ClientPort string `json:"clientPort"` // 客户端端口 LoginTime uint64 `json:"loginTime"` // 用户上次登录时间 @@ -32,78 +26,59 @@ type UserOnline struct { IsLogoff bool `json:"isLogoff"` // 是否下线 } -/********************** 数据处理 *********************************/ - -// 用户登录 -func UserLogin(accIp, accPort string, appId uint32, userId string, addr string, loginTime uint64) (userOnline *UserOnline) { - +// UserLogin 用户登录 +func UserLogin(accIp, accPort string, appID uint32, userID string, addr string, + loginTime uint64) (userOnline *UserOnline) { userOnline = &UserOnline{ AccIp: accIp, AccPort: accPort, - AppId: appId, - UserId: userId, + AppID: appID, + UserID: userID, ClientIp: addr, LoginTime: loginTime, HeartbeatTime: loginTime, IsLogoff: false, } - return } -// 用户心跳 +// Heartbeat 用户心跳 func (u *UserOnline) Heartbeat(currentTime uint64) { - u.HeartbeatTime = currentTime u.IsLogoff = false - return } -// 用户退出登录 +// LogOut 用户退出登录 func (u *UserOnline) LogOut() { - currentTime := uint64(time.Now().Unix()) u.LogOutTime = currentTime u.IsLogoff = true - return } -/********************** 数据操作 *********************************/ - -// 用户是否在线 +// IsOnline 用户是否在线 func (u *UserOnline) IsOnline() (online bool) { if u.IsLogoff { - return } - currentTime := uint64(time.Now().Unix()) - if u.HeartbeatTime < (currentTime - heartbeatTimeout) { - fmt.Println("用户是否在线 心跳超时", u.AppId, u.UserId, u.HeartbeatTime) - + fmt.Println("用户是否在线 心跳超时", u.AppID, u.UserID, u.HeartbeatTime) return } - if u.IsLogoff { - fmt.Println("用户是否在线 用户已经下线", u.AppId, u.UserId) - + fmt.Println("用户是否在线 用户已经下线", u.AppID, u.UserID) return } - return true } -// 用户是否在本台机器上 +// UserIsLocal 用户是否在本台机器上 func (u *UserOnline) UserIsLocal(localIp, localPort string) (result bool) { - if u.AccIp == localIp && u.AccPort == localPort { result = true - return } - return } diff --git a/protobuf/im_protobuf.pb.go b/protobuf/im_protobuf.pb.go index d05a916..25b22eb 100644 --- a/protobuf/im_protobuf.pb.go +++ b/protobuf/im_protobuf.pb.go @@ -1,13 +1,12 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.25.0 -// protoc v3.14.0 +// protoc-gen-go v1.31.0 +// protoc v4.24.3 // source: im_protobuf.proto package protobuf import ( - proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" @@ -21,18 +20,14 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -// This is a compile-time assertion that a sufficiently up-to-date version -// of the legacy proto package is being used. -const _ = proto.ProtoPackageIsVersion4 - // 查询用户是否在线 type QueryUsersOnlineReq struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - AppId uint32 `protobuf:"varint,1,opt,name=appId,proto3" json:"appId,omitempty"` // AppID - UserId string `protobuf:"bytes,2,opt,name=userId,proto3" json:"userId,omitempty"` // 用户ID + AppID uint32 `protobuf:"varint,1,opt,name=appID,proto3" json:"appID,omitempty"` // AppID + UserID string `protobuf:"bytes,2,opt,name=userID,proto3" json:"userID,omitempty"` // 用户ID } func (x *QueryUsersOnlineReq) Reset() { @@ -67,16 +62,16 @@ func (*QueryUsersOnlineReq) Descriptor() ([]byte, []int) { return file_im_protobuf_proto_rawDescGZIP(), []int{0} } -func (x *QueryUsersOnlineReq) GetAppId() uint32 { +func (x *QueryUsersOnlineReq) GetAppID() uint32 { if x != nil { - return x.AppId + return x.AppID } return 0 } -func (x *QueryUsersOnlineReq) GetUserId() string { +func (x *QueryUsersOnlineReq) GetUserID() string { if x != nil { - return x.UserId + return x.UserID } return "" } @@ -151,8 +146,8 @@ type SendMsgReq struct { unknownFields protoimpl.UnknownFields Seq string `protobuf:"bytes,1,opt,name=seq,proto3" json:"seq,omitempty"` // 序列号 - AppId uint32 `protobuf:"varint,2,opt,name=appId,proto3" json:"appId,omitempty"` // appId/房间Id - UserId string `protobuf:"bytes,3,opt,name=userId,proto3" json:"userId,omitempty"` // 用户ID + AppID uint32 `protobuf:"varint,2,opt,name=appID,proto3" json:"appID,omitempty"` // appID/房间ID + UserID string `protobuf:"bytes,3,opt,name=userID,proto3" json:"userID,omitempty"` // 用户ID Cms string `protobuf:"bytes,4,opt,name=cms,proto3" json:"cms,omitempty"` // cms 动作: msg/enter/exit Type string `protobuf:"bytes,5,opt,name=type,proto3" json:"type,omitempty"` // type 消息类型,默认是 text Msg string `protobuf:"bytes,6,opt,name=msg,proto3" json:"msg,omitempty"` // msg @@ -198,16 +193,16 @@ func (x *SendMsgReq) GetSeq() string { return "" } -func (x *SendMsgReq) GetAppId() uint32 { +func (x *SendMsgReq) GetAppID() uint32 { if x != nil { - return x.AppId + return x.AppID } return 0 } -func (x *SendMsgReq) GetUserId() string { +func (x *SendMsgReq) GetUserID() string { if x != nil { - return x.UserId + return x.UserID } return "" } @@ -247,7 +242,7 @@ type SendMsgRsp struct { RetCode uint32 `protobuf:"varint,1,opt,name=retCode,proto3" json:"retCode,omitempty"` ErrMsg string `protobuf:"bytes,2,opt,name=errMsg,proto3" json:"errMsg,omitempty"` - SendMsgId string `protobuf:"bytes,3,opt,name=sendMsgId,proto3" json:"sendMsgId,omitempty"` + SendMsgID string `protobuf:"bytes,3,opt,name=sendMsgID,proto3" json:"sendMsgID,omitempty"` } func (x *SendMsgRsp) Reset() { @@ -296,9 +291,9 @@ func (x *SendMsgRsp) GetErrMsg() string { return "" } -func (x *SendMsgRsp) GetSendMsgId() string { +func (x *SendMsgRsp) GetSendMsgID() string { if x != nil { - return x.SendMsgId + return x.SendMsgID } return "" } @@ -310,8 +305,8 @@ type SendMsgAllReq struct { unknownFields protoimpl.UnknownFields Seq string `protobuf:"bytes,1,opt,name=seq,proto3" json:"seq,omitempty"` // 序列号 - AppId uint32 `protobuf:"varint,2,opt,name=appId,proto3" json:"appId,omitempty"` // appId/房间Id - UserId string `protobuf:"bytes,3,opt,name=userId,proto3" json:"userId,omitempty"` // 不发送的用户ID + AppID uint32 `protobuf:"varint,2,opt,name=appID,proto3" json:"appID,omitempty"` // appID/房间ID + UserID string `protobuf:"bytes,3,opt,name=userID,proto3" json:"userID,omitempty"` // 不发送的用户ID Cms string `protobuf:"bytes,4,opt,name=cms,proto3" json:"cms,omitempty"` // cms 动作: msg/enter/exit Type string `protobuf:"bytes,5,opt,name=type,proto3" json:"type,omitempty"` // type 消息类型,默认是 text Msg string `protobuf:"bytes,6,opt,name=msg,proto3" json:"msg,omitempty"` // msg @@ -356,16 +351,16 @@ func (x *SendMsgAllReq) GetSeq() string { return "" } -func (x *SendMsgAllReq) GetAppId() uint32 { +func (x *SendMsgAllReq) GetAppID() uint32 { if x != nil { - return x.AppId + return x.AppID } return 0 } -func (x *SendMsgAllReq) GetUserId() string { +func (x *SendMsgAllReq) GetUserID() string { if x != nil { - return x.UserId + return x.UserID } return "" } @@ -398,7 +393,7 @@ type SendMsgAllRsp struct { RetCode uint32 `protobuf:"varint,1,opt,name=retCode,proto3" json:"retCode,omitempty"` ErrMsg string `protobuf:"bytes,2,opt,name=errMsg,proto3" json:"errMsg,omitempty"` - SendMsgId string `protobuf:"bytes,3,opt,name=sendMsgId,proto3" json:"sendMsgId,omitempty"` + SendMsgID string `protobuf:"bytes,3,opt,name=sendMsgID,proto3" json:"sendMsgID,omitempty"` } func (x *SendMsgAllRsp) Reset() { @@ -447,9 +442,9 @@ func (x *SendMsgAllRsp) GetErrMsg() string { return "" } -func (x *SendMsgAllRsp) GetSendMsgId() string { +func (x *SendMsgAllRsp) GetSendMsgID() string { if x != nil { - return x.SendMsgId + return x.SendMsgID } return "" } @@ -460,7 +455,7 @@ type GetUserListReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - AppId uint32 `protobuf:"varint,1,opt,name=appId,proto3" json:"appId,omitempty"` + AppID uint32 `protobuf:"varint,1,opt,name=appID,proto3" json:"appID,omitempty"` } func (x *GetUserListReq) Reset() { @@ -495,9 +490,9 @@ func (*GetUserListReq) Descriptor() ([]byte, []int) { return file_im_protobuf_proto_rawDescGZIP(), []int{6} } -func (x *GetUserListReq) GetAppId() uint32 { +func (x *GetUserListReq) GetAppID() uint32 { if x != nil { - return x.AppId + return x.AppID } return 0 } @@ -509,7 +504,7 @@ type GetUserListRsp struct { RetCode uint32 `protobuf:"varint,1,opt,name=retCode,proto3" json:"retCode,omitempty"` ErrMsg string `protobuf:"bytes,2,opt,name=errMsg,proto3" json:"errMsg,omitempty"` - UserId []string `protobuf:"bytes,3,rep,name=userId,proto3" json:"userId,omitempty"` + UserID []string `protobuf:"bytes,3,rep,name=userID,proto3" json:"userID,omitempty"` } func (x *GetUserListRsp) Reset() { @@ -558,9 +553,9 @@ func (x *GetUserListRsp) GetErrMsg() string { return "" } -func (x *GetUserListRsp) GetUserId() []string { +func (x *GetUserListRsp) GetUserID() []string { if x != nil { - return x.UserId + return x.UserID } return nil } @@ -571,10 +566,10 @@ var file_im_protobuf_proto_rawDesc = []byte{ 0x0a, 0x11, 0x69, 0x6d, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x22, 0x43, 0x0a, 0x13, 0x51, 0x75, 0x65, 0x72, 0x79, 0x55, 0x73, 0x65, 0x72, 0x73, 0x4f, 0x6e, 0x6c, 0x69, 0x6e, - 0x65, 0x52, 0x65, 0x71, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0d, 0x52, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, - 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, - 0x49, 0x64, 0x22, 0x5f, 0x0a, 0x13, 0x51, 0x75, 0x65, 0x72, 0x79, 0x55, 0x73, 0x65, 0x72, 0x73, + 0x65, 0x52, 0x65, 0x71, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x70, 0x70, 0x49, 0x44, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0d, 0x52, 0x05, 0x61, 0x70, 0x70, 0x49, 0x44, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, + 0x65, 0x72, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, + 0x49, 0x44, 0x22, 0x5f, 0x0a, 0x13, 0x51, 0x75, 0x65, 0x72, 0x79, 0x55, 0x73, 0x65, 0x72, 0x73, 0x4f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x73, 0x70, 0x12, 0x18, 0x0a, 0x07, 0x72, 0x65, 0x74, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x72, 0x65, 0x74, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x65, 0x72, 0x72, 0x4d, 0x73, 0x67, 0x18, 0x02, 0x20, @@ -582,10 +577,10 @@ var file_im_protobuf_proto_rawDesc = []byte{ 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x6f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x22, 0x9e, 0x01, 0x0a, 0x0a, 0x53, 0x65, 0x6e, 0x64, 0x4d, 0x73, 0x67, 0x52, 0x65, 0x71, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x65, 0x71, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x03, 0x73, 0x65, 0x71, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x0d, 0x52, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, - 0x65, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, - 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x63, 0x6d, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x03, 0x73, 0x65, 0x71, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x70, 0x70, 0x49, 0x44, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0d, 0x52, 0x05, 0x61, 0x70, 0x70, 0x49, 0x44, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, + 0x65, 0x72, 0x49, 0x44, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, + 0x49, 0x44, 0x12, 0x10, 0x0a, 0x03, 0x63, 0x6d, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x63, 0x6d, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x69, 0x73, @@ -595,13 +590,13 @@ var file_im_protobuf_proto_rawDesc = []byte{ 0x01, 0x28, 0x0d, 0x52, 0x07, 0x72, 0x65, 0x74, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x65, 0x72, 0x72, 0x4d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x65, 0x72, 0x72, 0x4d, 0x73, 0x67, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x65, 0x6e, 0x64, 0x4d, 0x73, 0x67, 0x49, - 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x65, 0x6e, 0x64, 0x4d, 0x73, 0x67, - 0x49, 0x64, 0x22, 0x87, 0x01, 0x0a, 0x0d, 0x53, 0x65, 0x6e, 0x64, 0x4d, 0x73, 0x67, 0x41, 0x6c, + 0x44, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x65, 0x6e, 0x64, 0x4d, 0x73, 0x67, + 0x49, 0x44, 0x22, 0x87, 0x01, 0x0a, 0x0d, 0x53, 0x65, 0x6e, 0x64, 0x4d, 0x73, 0x67, 0x41, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x65, 0x71, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x03, 0x73, 0x65, 0x71, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, - 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, - 0x65, 0x72, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x63, 0x6d, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x03, 0x73, 0x65, 0x71, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x70, 0x70, 0x49, 0x44, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x61, 0x70, 0x70, 0x49, 0x44, 0x12, 0x16, 0x0a, 0x06, + 0x75, 0x73, 0x65, 0x72, 0x49, 0x44, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, + 0x65, 0x72, 0x49, 0x44, 0x12, 0x10, 0x0a, 0x03, 0x63, 0x6d, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x63, 0x6d, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x22, 0x5f, 0x0a, 0x0d, @@ -609,17 +604,17 @@ var file_im_protobuf_proto_rawDesc = []byte{ 0x07, 0x72, 0x65, 0x74, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x72, 0x65, 0x74, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x65, 0x72, 0x72, 0x4d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x65, 0x72, 0x72, 0x4d, 0x73, 0x67, 0x12, - 0x1c, 0x0a, 0x09, 0x73, 0x65, 0x6e, 0x64, 0x4d, 0x73, 0x67, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x09, 0x73, 0x65, 0x6e, 0x64, 0x4d, 0x73, 0x67, 0x49, 0x64, 0x22, 0x26, 0x0a, + 0x1c, 0x0a, 0x09, 0x73, 0x65, 0x6e, 0x64, 0x4d, 0x73, 0x67, 0x49, 0x44, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x09, 0x73, 0x65, 0x6e, 0x64, 0x4d, 0x73, 0x67, 0x49, 0x44, 0x22, 0x26, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x12, - 0x14, 0x0a, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, - 0x61, 0x70, 0x70, 0x49, 0x64, 0x22, 0x5a, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, + 0x14, 0x0a, 0x05, 0x61, 0x70, 0x70, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, + 0x61, 0x70, 0x70, 0x49, 0x44, 0x22, 0x5a, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x73, 0x70, 0x12, 0x18, 0x0a, 0x07, 0x72, 0x65, 0x74, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x72, 0x65, 0x74, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x65, 0x72, 0x72, 0x4d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x65, 0x72, 0x72, 0x4d, 0x73, 0x67, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, - 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, - 0x64, 0x32, 0x9f, 0x02, 0x0a, 0x09, 0x41, 0x63, 0x63, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, + 0x72, 0x49, 0x44, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, + 0x44, 0x32, 0x9f, 0x02, 0x0a, 0x09, 0x41, 0x63, 0x63, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x52, 0x0a, 0x10, 0x51, 0x75, 0x65, 0x72, 0x79, 0x55, 0x73, 0x65, 0x72, 0x73, 0x4f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x1d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x55, 0x73, 0x65, 0x72, 0x73, 0x4f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x52, diff --git a/protobuf/im_protobuf.proto b/protobuf/im_protobuf.proto index 2a29624..e1e6e71 100644 --- a/protobuf/im_protobuf.proto +++ b/protobuf/im_protobuf.proto @@ -26,8 +26,8 @@ service AccServer { // 查询用户是否在线 message QueryUsersOnlineReq { - uint32 appId = 1; // AppID - string userId = 2; // 用户ID + uint32 appID = 1; // AppID + string userID = 2; // 用户ID } message QueryUsersOnlineRsp { @@ -39,8 +39,8 @@ message QueryUsersOnlineRsp { // 发送消息 message SendMsgReq { string seq = 1; // 序列号 - uint32 appId = 2; // appId/房间Id - string userId = 3; // 用户ID + uint32 appID = 2; // appID/房间ID + string userID = 3; // 用户ID string cms = 4; // cms 动作: msg/enter/exit string type = 5; // type 消息类型,默认是 text string msg = 6; // msg @@ -50,14 +50,14 @@ message SendMsgReq { message SendMsgRsp { uint32 retCode = 1; string errMsg = 2; - string sendMsgId = 3; + string sendMsgID = 3; } // 给这台机器的房间内所有用户发送消息 message SendMsgAllReq { string seq = 1; // 序列号 - uint32 appId = 2; // appId/房间Id - string userId = 3; // 不发送的用户ID + uint32 appID = 2; // appID/房间ID + string userID = 3; // 不发送的用户ID string cms = 4; // cms 动作: msg/enter/exit string type = 5; // type 消息类型,默认是 text string msg = 6; // msg @@ -66,16 +66,16 @@ message SendMsgAllReq { message SendMsgAllRsp { uint32 retCode = 1; string errMsg = 2; - string sendMsgId = 3; + string sendMsgID = 3; } // 获取用户列表 message GetUserListReq { - uint32 appId = 1; + uint32 appID = 1; } message GetUserListRsp { uint32 retCode = 1; string errMsg = 2; - repeated string userId = 3; + repeated string userID = 3; } \ No newline at end of file diff --git a/protobuf/im_protobuf_grpc.pb.go b/protobuf/im_protobuf_grpc.pb.go index 5a64cbb..b0ab609 100644 --- a/protobuf/im_protobuf_grpc.pb.go +++ b/protobuf/im_protobuf_grpc.pb.go @@ -1,4 +1,8 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc v4.24.3 +// source: im_protobuf.proto package protobuf @@ -14,6 +18,13 @@ import ( // Requires gRPC-Go v1.32.0 or later. const _ = grpc.SupportPackageIsVersion7 +const ( + AccServer_QueryUsersOnline_FullMethodName = "/protobuf.AccServer/QueryUsersOnline" + AccServer_SendMsg_FullMethodName = "/protobuf.AccServer/SendMsg" + AccServer_SendMsgAll_FullMethodName = "/protobuf.AccServer/SendMsgAll" + AccServer_GetUserList_FullMethodName = "/protobuf.AccServer/GetUserList" +) + // AccServerClient is the client API for AccServer service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. @@ -38,7 +49,7 @@ func NewAccServerClient(cc grpc.ClientConnInterface) AccServerClient { func (c *accServerClient) QueryUsersOnline(ctx context.Context, in *QueryUsersOnlineReq, opts ...grpc.CallOption) (*QueryUsersOnlineRsp, error) { out := new(QueryUsersOnlineRsp) - err := c.cc.Invoke(ctx, "/protobuf.AccServer/QueryUsersOnline", in, out, opts...) + err := c.cc.Invoke(ctx, AccServer_QueryUsersOnline_FullMethodName, in, out, opts...) if err != nil { return nil, err } @@ -47,7 +58,7 @@ func (c *accServerClient) QueryUsersOnline(ctx context.Context, in *QueryUsersOn func (c *accServerClient) SendMsg(ctx context.Context, in *SendMsgReq, opts ...grpc.CallOption) (*SendMsgRsp, error) { out := new(SendMsgRsp) - err := c.cc.Invoke(ctx, "/protobuf.AccServer/SendMsg", in, out, opts...) + err := c.cc.Invoke(ctx, AccServer_SendMsg_FullMethodName, in, out, opts...) if err != nil { return nil, err } @@ -56,7 +67,7 @@ func (c *accServerClient) SendMsg(ctx context.Context, in *SendMsgReq, opts ...g func (c *accServerClient) SendMsgAll(ctx context.Context, in *SendMsgAllReq, opts ...grpc.CallOption) (*SendMsgAllRsp, error) { out := new(SendMsgAllRsp) - err := c.cc.Invoke(ctx, "/protobuf.AccServer/SendMsgAll", in, out, opts...) + err := c.cc.Invoke(ctx, AccServer_SendMsgAll_FullMethodName, in, out, opts...) if err != nil { return nil, err } @@ -65,7 +76,7 @@ func (c *accServerClient) SendMsgAll(ctx context.Context, in *SendMsgAllReq, opt func (c *accServerClient) GetUserList(ctx context.Context, in *GetUserListReq, opts ...grpc.CallOption) (*GetUserListRsp, error) { out := new(GetUserListRsp) - err := c.cc.Invoke(ctx, "/protobuf.AccServer/GetUserList", in, out, opts...) + err := c.cc.Invoke(ctx, AccServer_GetUserList_FullMethodName, in, out, opts...) if err != nil { return nil, err } @@ -126,7 +137,7 @@ func _AccServer_QueryUsersOnline_Handler(srv interface{}, ctx context.Context, d } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/protobuf.AccServer/QueryUsersOnline", + FullMethod: AccServer_QueryUsersOnline_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(AccServerServer).QueryUsersOnline(ctx, req.(*QueryUsersOnlineReq)) @@ -144,7 +155,7 @@ func _AccServer_SendMsg_Handler(srv interface{}, ctx context.Context, dec func(i } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/protobuf.AccServer/SendMsg", + FullMethod: AccServer_SendMsg_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(AccServerServer).SendMsg(ctx, req.(*SendMsgReq)) @@ -162,7 +173,7 @@ func _AccServer_SendMsgAll_Handler(srv interface{}, ctx context.Context, dec fun } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/protobuf.AccServer/SendMsgAll", + FullMethod: AccServer_SendMsgAll_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(AccServerServer).SendMsgAll(ctx, req.(*SendMsgAllReq)) @@ -180,7 +191,7 @@ func _AccServer_GetUserList_Handler(srv interface{}, ctx context.Context, dec fu } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/protobuf.AccServer/GetUserList", + FullMethod: AccServer_GetUserList_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(AccServerServer).GetUserList(ctx, req.(*GetUserListReq)) diff --git a/routers/acc_routers.go b/routers/acc_routers.go index 86e7f78..1b9408e 100644 --- a/routers/acc_routers.go +++ b/routers/acc_routers.go @@ -1,17 +1,11 @@ -/** - * Created by GoLand. - * User: link1st - * Date: 2019-07-25 - * Time: 16:02 - */ - +// Package routers 路由 package routers import ( - "gowebsocket/servers/websocket" + "github.com/link1st/gowebsocket/v2/servers/websocket" ) -// Websocket 路由 +// WebsocketInit Websocket 路由 func WebsocketInit() { websocket.Register("login", websocket.LoginController) websocket.Register("heartbeat", websocket.HeartbeatController) diff --git a/routers/web_routers.go b/routers/web_routers.go index 24d2a7d..5b325f7 100644 --- a/routers/web_routers.go +++ b/routers/web_routers.go @@ -1,19 +1,15 @@ -/** -* Created by GoLand. -* User: link1st -* Date: 2019-07-25 -* Time: 12:20 - */ - +// Package routers 路由 package routers import ( "github.com/gin-gonic/gin" - "gowebsocket/controllers/home" - "gowebsocket/controllers/systems" - "gowebsocket/controllers/user" + + "github.com/link1st/gowebsocket/v2/controllers/home" + "github.com/link1st/gowebsocket/v2/controllers/systems" + "github.com/link1st/gowebsocket/v2/controllers/user" ) +// Init http 接口路由 func Init(router *gin.Engine) { router.LoadHTMLGlob("views/**/*") @@ -37,6 +33,4 @@ func Init(router *gin.Engine) { { homeRouter.GET("/index", home.Index) } - - // router.POST("/user/online", user.Online) } diff --git a/servers/grpcclient/grpc_client.go b/servers/grpcclient/grpc_client.go index 04427e8..61a3878 100644 --- a/servers/grpcclient/grpc_client.go +++ b/servers/grpcclient/grpc_client.go @@ -1,44 +1,39 @@ -/** -* Created by GoLand. -* User: link1st -* Date: 2019-08-03 -* Time: 16:43 - */ - +// Package grpcclient grpc 客户端 package grpcclient import ( "context" "errors" "fmt" - "google.golang.org/grpc" - "gowebsocket/common" - "gowebsocket/models" - "gowebsocket/protobuf" "time" + + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" + + "github.com/link1st/gowebsocket/v2/common" + "github.com/link1st/gowebsocket/v2/models" + "github.com/link1st/gowebsocket/v2/protobuf" ) -// rpc client -// 给全体用户发送消息 +// SendMsgAll 给全体用户发送消息 // link::https://github.com/grpc/grpc-go/blob/master/examples/helloworld/greeter_client/main.go -func SendMsgAll(server *models.Server, seq string, appId uint32, userId string, cmd string, message string) (sendMsgId string, err error) { +func SendMsgAll(server *models.Server, seq string, appID uint32, userID string, cmd string, + message string) (sendMsgID string, err error) { // Set up a connection to the server. - conn, err := grpc.Dial(server.String(), grpc.WithInsecure()) + conn, err := grpc.Dial(server.String(), grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { fmt.Println("连接失败", server.String()) return } - defer conn.Close() - + defer func() { _ = conn.Close() }() c := protobuf.NewAccServerClient(conn) ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() - req := protobuf.SendMsgAllReq{ Seq: seq, - AppId: appId, - UserId: userId, + AppID: appID, + UserID: userID, Cms: cmd, Msg: message, } @@ -48,81 +43,66 @@ func SendMsgAll(server *models.Server, seq string, appId uint32, userId string, return } - if rsp.GetRetCode() != common.OK { fmt.Println("给全体用户发送消息", rsp.String()) err = errors.New(fmt.Sprintf("发送消息失败 code:%d", rsp.GetRetCode())) return } - - sendMsgId = rsp.GetSendMsgId() - fmt.Println("给全体用户发送消息 成功:", sendMsgId) - + sendMsgID = rsp.GetSendMsgID() + fmt.Println("给全体用户发送消息 成功:", sendMsgID) return } -// 获取用户列表 +// GetUserList 获取用户列表 // link::https://github.com/grpc/grpc-go/blob/master/examples/helloworld/greeter_client/main.go -func GetUserList(server *models.Server, appId uint32) (userIds []string, err error) { - userIds = make([]string, 0) - - conn, err := grpc.Dial(server.String(), grpc.WithInsecure()) +func GetUserList(server *models.Server, appID uint32) (userIDs []string, err error) { + userIDs = make([]string, 0) + conn, err := grpc.Dial(server.String(), grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { fmt.Println("连接失败", server.String()) - return } - defer conn.Close() - + defer func() { _ = conn.Close() }() c := protobuf.NewAccServerClient(conn) ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() - req := protobuf.GetUserListReq{ - AppId: appId, + AppID: appID, } rsp, err := c.GetUserList(ctx, &req) if err != nil { fmt.Println("获取用户列表 发送请求错误:", err) - return } - if rsp.GetRetCode() != common.OK { fmt.Println("获取用户列表 返回码错误:", rsp.String()) err = errors.New(fmt.Sprintf("发送消息失败 code:%d", rsp.GetRetCode())) - return } - - userIds = rsp.GetUserId() - fmt.Println("获取用户列表 成功:", userIds) - + userIDs = rsp.GetUserID() + fmt.Println("获取用户列表 成功:", userIDs) return } -// rpc client -// 发送消息 +// SendMsg 发送消息 // link::https://github.com/grpc/grpc-go/blob/master/examples/helloworld/greeter_client/main.go -func SendMsg(server *models.Server, seq string, appId uint32, userId string, cmd string, msgType string, message string) (sendMsgId string, err error) { +func SendMsg(server *models.Server, seq string, appID uint32, userID string, cmd string, msgType string, + message string) (sendMsgID string, err error) { // Set up a connection to the server. - conn, err := grpc.Dial(server.String(), grpc.WithInsecure()) + conn, err := grpc.Dial(server.String(), grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { fmt.Println("连接失败", server.String()) - return } - defer conn.Close() - + defer func() { _ = conn.Close() }() c := protobuf.NewAccServerClient(conn) ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() - req := protobuf.SendMsgReq{ Seq: seq, - AppId: appId, - UserId: userId, + AppID: appID, + UserID: userID, Cms: cmd, Type: msgType, Msg: message, @@ -131,19 +111,14 @@ func SendMsg(server *models.Server, seq string, appId uint32, userId string, cmd rsp, err := c.SendMsg(ctx, &req) if err != nil { fmt.Println("发送消息", err) - return } - if rsp.GetRetCode() != common.OK { fmt.Println("发送消息", rsp.String()) err = errors.New(fmt.Sprintf("发送消息失败 code:%d", rsp.GetRetCode())) - return } - - sendMsgId = rsp.GetSendMsgId() - fmt.Println("发送消息 成功:", sendMsgId) - + sendMsgID = rsp.GetSendMsgID() + fmt.Println("发送消息 成功:", sendMsgID) return } diff --git a/servers/grpcserver/grpc_server.go b/servers/grpcserver/grpc_server.go index d6c2bf3..c54f08c 100644 --- a/servers/grpcserver/grpc_server.go +++ b/servers/grpcserver/grpc_server.go @@ -1,10 +1,4 @@ -/** -* Created by GoLand. -* User: link1st -* Date: 2019-08-03 -* Time: 16:43 - */ - +// Package grpcserver grpc 服务器 package grpcserver import ( @@ -13,10 +7,10 @@ import ( "log" "net" - "gowebsocket/common" - "gowebsocket/models" - "gowebsocket/protobuf" - "gowebsocket/servers/websocket" + "github.com/link1st/gowebsocket/v2/common" + "github.com/link1st/gowebsocket/v2/models" + "github.com/link1st/gowebsocket/v2/protobuf" + "github.com/link1st/gowebsocket/v2/servers/websocket" "github.com/golang/protobuf/proto" "github.com/spf13/viper" @@ -28,7 +22,6 @@ type server struct { } func setErr(rsp proto.Message, code uint32, message string) { - message = common.GetErrorMessage(code, message) switch v := rsp.(type) { case *protobuf.QueryUsersOnlineRsp: @@ -44,12 +37,10 @@ func setErr(rsp proto.Message, code uint32, message string) { v.RetCode = code v.ErrMsg = message default: - } - } -// 查询用户是否在线 +// QueryUsersOnline 查询用户是否在线 func (s *server) QueryUsersOnline(c context.Context, req *protobuf.QueryUsersOnlineReq) (rsp *protobuf.QueryUsersOnlineRsp, err error) { @@ -57,7 +48,7 @@ func (s *server) QueryUsersOnline(c context.Context, rsp = &protobuf.QueryUsersOnlineRsp{} - online := websocket.CheckUserOnline(req.GetAppId(), req.GetUserId()) + online := websocket.CheckUserOnline(req.GetAppID(), req.GetUserID()) setErr(req, common.OK, "") rsp.Online = online @@ -65,87 +56,68 @@ func (s *server) QueryUsersOnline(c context.Context, return rsp, nil } -// 给本机用户发消息 +// SendMsg 给本机用户发消息 func (s *server) SendMsg(c context.Context, req *protobuf.SendMsgReq) (rsp *protobuf.SendMsgRsp, err error) { - fmt.Println("grpc_request 给本机用户发消息", req.String()) - rsp = &protobuf.SendMsgRsp{} - if req.GetIsLocal() { - // 不支持 setErr(rsp, common.ParameterIllegal, "") - return } - - data := models.GetMsgData(req.GetUserId(), req.GetSeq(), req.GetCms(), req.GetMsg()) - sendResults, err := websocket.SendUserMessageLocal(req.GetAppId(), req.GetUserId(), data) + data := models.GetMsgData(req.GetUserID(), req.GetSeq(), req.GetCms(), req.GetMsg()) + sendResults, err := websocket.SendUserMessageLocal(req.GetAppID(), req.GetUserID(), data) if err != nil { fmt.Println("系统错误", err) setErr(rsp, common.ServerError, "") - return rsp, nil } - if !sendResults { fmt.Println("发送失败", err) setErr(rsp, common.OperationFailure, "") - return rsp, nil } - setErr(rsp, common.OK, "") - fmt.Println("grpc_response 给本机用户发消息", rsp.String()) return } -// 给本机全体用户发消息 +// SendMsgAll 给本机全体用户发消息 func (s *server) SendMsgAll(c context.Context, req *protobuf.SendMsgAllReq) (rsp *protobuf.SendMsgAllRsp, err error) { - fmt.Println("grpc_request 给本机全体用户发消息", req.String()) - rsp = &protobuf.SendMsgAllRsp{} - - data := models.GetMsgData(req.GetUserId(), req.GetSeq(), req.GetCms(), req.GetMsg()) - websocket.AllSendMessages(req.GetAppId(), req.GetUserId(), data) - + data := models.GetMsgData(req.GetUserID(), req.GetSeq(), req.GetCms(), req.GetMsg()) + websocket.AllSendMessages(req.GetAppID(), req.GetUserID(), data) setErr(rsp, common.OK, "") - fmt.Println("grpc_response 给本机全体用户发消息:", rsp.String()) - return } -// 获取本机用户列表 +// GetUserList 获取本机用户列表 func (s *server) GetUserList(c context.Context, req *protobuf.GetUserListReq) (rsp *protobuf.GetUserListRsp, err error) { fmt.Println("grpc_request 获取本机用户列表", req.String()) - appId := req.GetAppId() + appID := req.GetAppID() rsp = &protobuf.GetUserListRsp{} // 本机 - userList := websocket.GetUserList(appId) + userList := websocket.GetUserList(appID) setErr(rsp, common.OK, "") - rsp.UserId = userList + rsp.UserID = userList fmt.Println("grpc_response 获取本机用户列表:", rsp.String()) return } -// rpc server +// Init rpc server // link::https://github.com/grpc/grpc-go/blob/master/examples/helloworld/greeter_server/main.go func Init() { - rpcPort := viper.GetString("app.rpcPort") fmt.Println("rpc server 启动", rpcPort) - lis, err := net.Listen("tcp", ":"+rpcPort) if err != nil { log.Fatalf("failed to listen: %v", err) diff --git a/servers/task/clean_connection _task.go b/servers/task/clean_connection _task.go index e98cfe8..0645103 100644 --- a/servers/task/clean_connection _task.go +++ b/servers/task/clean_connection _task.go @@ -1,37 +1,29 @@ -/** -* Created by GoLand. -* User: link1st -* Date: 2019-07-31 -* Time: 15:17 - */ - +// Package task 定时任务 package task import ( "fmt" - "gowebsocket/servers/websocket" "runtime/debug" "time" + + "github.com/link1st/gowebsocket/v2/servers/websocket" ) +// Init 初始化 func Init() { Timer(3*time.Second, 30*time.Second, cleanConnection, "", nil, nil) } -// 清理超时连接 +// cleanConnection 清理超时连接 func cleanConnection(param interface{}) (result bool) { result = true - defer func() { if r := recover(); r != nil { fmt.Println("ClearTimeoutConnections stop", r, string(debug.Stack())) } }() - fmt.Println("定时任务,清理超时连接", param) - websocket.ClearTimeoutConnections() - return } diff --git a/servers/task/server_task.go b/servers/task/server_task.go index 9b03c44..ab119de 100644 --- a/servers/task/server_task.go +++ b/servers/task/server_task.go @@ -1,55 +1,44 @@ -/** -* Created by GoLand. -* User: link1st -* Date: 2019-08-03 -* Time: 15:44 - */ - +// Package task 定时任务 package task import ( "fmt" - "gowebsocket/lib/cache" - "gowebsocket/servers/websocket" "runtime/debug" "time" + + "github.com/link1st/gowebsocket/v2/lib/cache" + "github.com/link1st/gowebsocket/v2/servers/websocket" ) +// ServerInit 服务初始化 func ServerInit() { Timer(2*time.Second, 60*time.Second, server, "", serverDefer, "") } -// 服务注册 +// server 服务注册 func server(param interface{}) (result bool) { result = true - defer func() { if r := recover(); r != nil { fmt.Println("服务注册 stop", r, string(debug.Stack())) } }() - - server := websocket.GetServer() + s := websocket.GetServer() currentTime := uint64(time.Now().Unix()) - fmt.Println("定时任务,服务注册", param, server, currentTime) - - cache.SetServerInfo(server, currentTime) - + fmt.Println("定时任务,服务注册", param, s, currentTime) + _ = cache.SetServerInfo(s, currentTime) return } -// 服务下线 +// serverDefer 服务下线 func serverDefer(param interface{}) (result bool) { defer func() { if r := recover(); r != nil { fmt.Println("服务下线 stop", r, string(debug.Stack())) } }() - fmt.Println("服务下线", param) - - server := websocket.GetServer() - cache.DelServerInfo(server) - + s := websocket.GetServer() + _ = cache.DelServerInfo(s) return } diff --git a/servers/task/task_init.go b/servers/task/task_init.go index 9495d9d..d90b9bd 100644 --- a/servers/task/task_init.go +++ b/servers/task/task_init.go @@ -1,23 +1,17 @@ -/** -* Created by GoLand. -* User: link1st -* Date: 2019-07-29 -* Time: 14:15 - */ - +// Package task 定时任务 package task import "time" +// TimerFunc 定时任务函数 type TimerFunc func(interface{}) bool -/** - * 定时调用 - * @delay 首次延时 - * @tick 间隔 - * @fun 定时执行function - * @param fun参数 - */ +// Timer 定时调用 +// +// @delay 首次延时 +// @tick 间隔 +// @fun 定时执行function +// @param fun参数 func Timer(delay, tick time.Duration, fun TimerFunc, param interface{}, funcDefer TimerFunc, paramDefer interface{}) { go func() { defer func() { @@ -25,14 +19,11 @@ func Timer(delay, tick time.Duration, fun TimerFunc, param interface{}, funcDefe funcDefer(paramDefer) } }() - if fun == nil { return } - t := time.NewTimer(delay) defer t.Stop() - for { select { case <-t.c: diff --git a/servers/websocket/acc_controller.go b/servers/websocket/acc_controller.go index ad2a858..a19f617 100644 --- a/servers/websocket/acc_controller.go +++ b/servers/websocket/acc_controller.go @@ -1,144 +1,114 @@ -/** - * Created by GoLand. - * User: link1st - * Date: 2019-07-27 - * Time: 13:12 - */ - +// Package websocket 处理 package websocket import ( "encoding/json" + "errors" "fmt" - "github.com/go-redis/redis" - "gowebsocket/common" - "gowebsocket/lib/cache" - "gowebsocket/models" "time" + + "github.com/link1st/gowebsocket/v2/common" + "github.com/link1st/gowebsocket/v2/lib/cache" + "github.com/link1st/gowebsocket/v2/models" + + "github.com/redis/go-redis/v9" ) -// ping +// PingController ping func PingController(client *Client, seq string, message []byte) (code uint32, msg string, data interface{}) { - code = common.OK fmt.Println("webSocket_request ping接口", client.Addr, seq, message) - data = "pong" - return } -// 用户登录 +// LoginController 用户登录 func LoginController(client *Client, seq string, message []byte) (code uint32, msg string, data interface{}) { - code = common.OK currentTime := uint64(time.Now().Unix()) - request := &models.Login{} if err := json.Unmarshal(message, request); err != nil { code = common.ParameterIllegal fmt.Println("用户登录 解析数据失败", seq, err) - return } - fmt.Println("webSocket_request 用户登录", seq, "ServiceToken", request.ServiceToken) // TODO::进行用户权限认证,一般是客户端传入TOKEN,然后检验TOKEN是否合法,通过TOKEN解析出来用户ID // 本项目只是演示,所以直接过去客户端传入的用户ID - if request.UserId == "" || len(request.UserId)>= 20 { - code = common.UnauthorizedUserId - fmt.Println("用户登录 非法的用户", seq, request.UserId) - + if request.UserID == "" || len(request.UserID)>= 20 { + code = common.UnauthorizedUserID + fmt.Println("用户登录 非法的用户", seq, request.UserID) return } - - if !InAppIds(request.AppId) { + if !InAppIDs(request.AppID) { code = common.Unauthorized - fmt.Println("用户登录 不支持的平台", seq, request.AppId) - + fmt.Println("用户登录 不支持的平台", seq, request.AppID) return } - if client.IsLogin() { - fmt.Println("用户登录 用户已经登录", client.AppId, client.UserId, seq) + fmt.Println("用户登录 用户已经登录", client.AppID, client.UserID, seq) code = common.OperationFailure - return } - - client.Login(request.AppId, request.UserId, currentTime) + client.Login(request.AppID, request.UserID, currentTime) // 存储数据 - userOnline := models.UserLogin(serverIp, serverPort, request.AppId, request.UserId, client.Addr, currentTime) + userOnline := models.UserLogin(serverIp, serverPort, request.AppID, request.UserID, client.Addr, currentTime) err := cache.SetUserOnlineInfo(client.GetKey(), userOnline) if err != nil { code = common.ServerError fmt.Println("用户登录 SetUserOnlineInfo", seq, err) - return } // 用户登录 login := &login{ - AppId: request.AppId, - UserId: request.UserId, + AppID: request.AppID, + UserID: request.UserID, Client: client, } clientManager.Login <- login - - fmt.Println("用户登录 成功", seq, client.Addr, request.UserId) + fmt.Println("用户登录 成功", seq, client.Addr, request.UserID) return } -// 心跳接口 +// HeartbeatController 心跳接口 func HeartbeatController(client *Client, seq string, message []byte) (code uint32, msg string, data interface{}) { - code = common.OK currentTime := uint64(time.Now().Unix()) - request := &models.HeartBeat{} if err := json.Unmarshal(message, request); err != nil { code = common.ParameterIllegal fmt.Println("心跳接口 解析数据失败", seq, err) - return } - - fmt.Println("webSocket_request 心跳接口", client.AppId, client.UserId) - + fmt.Println("webSocket_request 心跳接口", client.AppID, client.UserID) if !client.IsLogin() { - fmt.Println("心跳接口 用户未登录", client.AppId, client.UserId, seq) + fmt.Println("心跳接口 用户未登录", client.AppID, client.UserID, seq) code = common.NotLoggedIn - return } - userOnline, err := cache.GetUserOnlineInfo(client.GetKey()) if err != nil { - if err == redis.Nil { + if errors.Is(err, redis.Nil) { code = common.NotLoggedIn - fmt.Println("心跳接口 用户未登录", seq, client.AppId, client.UserId) - + fmt.Println("心跳接口 用户未登录", seq, client.AppID, client.UserID) return } else { code = common.ServerError - fmt.Println("心跳接口 GetUserOnlineInfo", seq, client.AppId, client.UserId, err) - + fmt.Println("心跳接口 GetUserOnlineInfo", seq, client.AppID, client.UserID, err) return } } - client.Heartbeat(currentTime) userOnline.Heartbeat(currentTime) err = cache.SetUserOnlineInfo(client.GetKey(), userOnline) if err != nil { code = common.ServerError - fmt.Println("心跳接口 SetUserOnlineInfo", seq, client.AppId, client.UserId, err) - + fmt.Println("心跳接口 SetUserOnlineInfo", seq, client.AppID, client.UserID, err) return } - return } diff --git a/servers/websocket/acc_process.go b/servers/websocket/acc_process.go index 54c00ac..d27de74 100644 --- a/servers/websocket/acc_process.go +++ b/servers/websocket/acc_process.go @@ -1,20 +1,16 @@ -/** - * Created by GoLand. - * User: link1st - * Date: 2019-07-27 - * Time: 14:38 - */ - +// Package websocket 处理 package websocket import ( "encoding/json" "fmt" - "gowebsocket/common" - "gowebsocket/models" "sync" + + "github.com/link1st/gowebsocket/v2/common" + "github.com/link1st/gowebsocket/v2/models" ) +// DisposeFunc 处理函数 type DisposeFunc func(client *Client, seq string, message []byte) (code uint32, msg string, data interface{}) var ( @@ -22,56 +18,43 @@ var ( handlersRWMutex sync.RWMutex ) -// 注册 +// Register 注册 func Register(key string, value DisposeFunc) { handlersRWMutex.Lock() defer handlersRWMutex.Unlock() handlers[key] = value - return } func getHandlers(key string) (value DisposeFunc, ok bool) { handlersRWMutex.RLock() defer handlersRWMutex.RUnlock() - value, ok = handlers[key] - return } -// 处理数据 +// ProcessData 处理数据 func ProcessData(client *Client, message []byte) { - fmt.Println("处理数据", client.Addr, string(message)) - defer func() { if r := recover(); r != nil { fmt.Println("处理数据 stop", r) } }() - request := &models.Request{} - - err := json.Unmarshal(message, request) - if err != nil { + if err := json.Unmarshal(message, request); err != nil { fmt.Println("处理数据 json Unmarshal", err) client.SendMsg([]byte("数据不合法")) - return } - requestData, err := json.Marshal(request.Data) if err != nil { fmt.Println("处理数据 json Marshal", err) client.SendMsg([]byte("处理数据失败")) - return } - seq := request.Seq cmd := request.Cmd - var ( code uint32 msg string @@ -88,21 +71,14 @@ func ProcessData(client *Client, message []byte) { code = common.RoutingNotExist fmt.Println("处理数据 路由不存在", client.Addr, "cmd", cmd) } - msg = common.GetErrorMessage(code, msg) - responseHead := models.NewResponseHead(seq, cmd, code, msg, data) - headByte, err := json.Marshal(responseHead) if err != nil { fmt.Println("处理数据 json Marshal", err) - return } - client.SendMsg(headByte) - - fmt.Println("acc_response send", client.Addr, client.AppId, client.UserId, "cmd", cmd, "code", code) - + fmt.Println("acc_response send", client.Addr, client.AppID, client.UserID, "cmd", cmd, "code", code) return } diff --git a/servers/websocket/client.go b/servers/websocket/client.go index 6ed4349..8139bcf 100644 --- a/servers/websocket/client.go +++ b/servers/websocket/client.go @@ -1,16 +1,11 @@ -/** - * Created by GoLand. - * User: link1st - * Date: 2019-07-25 - * Time: 16:24 - */ - +// Package websocket 处理 package websocket import ( "fmt" - "github.com/gorilla/websocket" "runtime/debug" + + "github.com/gorilla/websocket" ) const ( @@ -20,31 +15,31 @@ const ( // 用户登录 type login struct { - AppId uint32 - UserId string + AppID uint32 + UserID string Client *Client } -// 读取客户端数据 +// GetKey 获取 key func (l *login) GetKey() (key string) { - key = GetUserKey(l.AppId, l.UserId) + key = GetUserKey(l.AppID, l.UserID) return } -// 用户连接 +// Client 用户连接 type Client struct { Addr string // 客户端地址 Socket *websocket.Conn // 用户连接 Send chan []byte // 待发送的数据 - AppId uint32 // 登录的平台Id app/web/ios - UserId string // 用户Id,用户登录以后才有 + AppID uint32 // 登录的平台ID app/web/ios + UserID string // 用户ID,用户登录以后才有 FirstTime uint64 // 首次连接事件 HeartbeatTime uint64 // 用户上次心跳时间 LoginTime uint64 // 登录时间 登录以后才有 } -// 初始化 +// NewClient 初始化 func NewClient(addr string, socket *websocket.Conn, firstTime uint64) (client *Client) { client = &Client{ Addr: addr, @@ -53,14 +48,12 @@ func NewClient(addr string, socket *websocket.Conn, firstTime uint64) (client *C FirstTime: firstTime, HeartbeatTime: firstTime, } - return } -// 读取客户端数据 +// GetKey 获取 key func (c *Client) GetKey() (key string) { - key = GetUserKey(c.AppId, c.UserId) - + key = GetUserKey(c.AppID, c.UserID) return } @@ -71,17 +64,14 @@ func (c *Client) read() { fmt.Println("write stop", string(debug.Stack()), r) } }() - defer func() { fmt.Println("读取客户端数据 关闭send", c) close(c.Send) }() - for { _, message, err := c.Socket.ReadMessage() if err != nil { fmt.Println("读取客户端数据 错误", c.Addr, err) - return } @@ -96,87 +86,74 @@ func (c *Client) write() { defer func() { if r := recover(); r != nil { fmt.Println("write stop", string(debug.Stack()), r) - } }() - defer func() { clientManager.Unregister <- c - c.Socket.Close() + _ = c.Socket.Close() fmt.Println("Client发送数据 defer", c) }() - for { select { case message, ok := <-c.send: if !ok { // 发送数据错误 关闭连接 fmt.Println("Client发送数据 关闭连接", c.Addr, "ok", ok) - return } - - c.Socket.WriteMessage(websocket.TextMessage, message) + _ = c.Socket.WriteMessage(websocket.TextMessage, message) } } } -// 读取客户端数据 +// SendMsg 发送数据 func (c *Client) SendMsg(msg []byte) { - if c == nil { - return } - defer func() { if r := recover(); r != nil { fmt.Println("SendMsg stop:", r, string(debug.Stack())) } }() - c.Send <- msg } -// 读取客户端数据 +// close 关闭客户端连接 func (c *Client) close() { close(c.Send) } -// 用户登录 -func (c *Client) Login(appId uint32, userId string, loginTime uint64) { - c.AppId = appId - c.UserId = userId +// Login 用户登录 +func (c *Client) Login(appID uint32, userID string, loginTime uint64) { + c.AppID = appID + c.UserID = userID c.LoginTime = loginTime // 登录成功=心跳一次 c.Heartbeat(loginTime) } -// 用户心跳 +// Heartbeat 用户心跳 func (c *Client) Heartbeat(currentTime uint64) { c.HeartbeatTime = currentTime return } -// 心跳超时 +// IsHeartbeatTimeout 心跳超时 func (c *Client) IsHeartbeatTimeout(currentTime uint64) (timeout bool) { if c.HeartbeatTime+heartbeatExpirationTime <= currentTime { timeout = true } - return } -// 是否登录了 +// IsLogin 是否登录了 func (c *Client) IsLogin() (isLogin bool) { - // 用户登录了 - if c.UserId != "" { + if c.UserID != "" { isLogin = true - return } - return } diff --git a/servers/websocket/client_manager.go b/servers/websocket/client_manager.go index ba0a1f5..75a1694 100644 --- a/servers/websocket/client_manager.go +++ b/servers/websocket/client_manager.go @@ -1,26 +1,21 @@ -/** - * Created by GoLand. - * User: link1st - * Date: 2019-07-25 - * Time: 16:24 - */ - +// Package websocket 处理 package websocket import ( "fmt" - "gowebsocket/helper" - "gowebsocket/lib/cache" - "gowebsocket/models" "sync" "time" + + "github.com/link1st/gowebsocket/v2/helper" + "github.com/link1st/gowebsocket/v2/lib/cache" + "github.com/link1st/gowebsocket/v2/models" ) -// 连接管理 +// ClientManager 连接管理 type ClientManager struct { Clients map[*Client]bool // 全部的连接 ClientsLock sync.RWMutex // 读写锁 - Users map[string]*Client // 登录的用户 // appId+uuid + Users map[string]*Client // 登录的用户 // appID+uuid UserLock sync.RWMutex // 读写锁 Register chan *Client // 连接连接处理 Login chan *login // 用户登录处理 @@ -28,6 +23,7 @@ type ClientManager struct { Broadcast chan []byte // 广播 向全部成员发送数据 } +// NewClientManager 创建连接管理 func NewClientManager() (clientManager *ClientManager) { clientManager = &ClientManager{ Clients: make(map[*Client]bool), @@ -37,181 +33,145 @@ func NewClientManager() (clientManager *ClientManager) { Unregister: make(chan *Client, 1000), Broadcast: make(chan []byte, 1000), } - return } -// 获取用户key -func GetUserKey(appId uint32, userId string) (key string) { - key = fmt.Sprintf("%d_%s", appId, userId) - +// GetUserKey 获取用户key +func GetUserKey(appID uint32, userID string) (key string) { + key = fmt.Sprintf("%d_%s", appID, userID) return } -/************************** manager ***************************************/ - func (manager *ClientManager) InClient(client *Client) (ok bool) { manager.ClientsLock.RLock() defer manager.ClientsLock.RUnlock() // 连接存在,在添加 _, ok = manager.Clients[client] - return } -// GetClients +// GetClients 获取所有客户端 func (manager *ClientManager) GetClients() (clients map[*Client]bool) { - clients = make(map[*Client]bool) - manager.ClientsRange(func(client *Client, value bool) (result bool) { clients[client] = value - return true }) - return } -// 遍历 +// ClientsRange 遍历 func (manager *ClientManager) ClientsRange(f func(client *Client, value bool) (result bool)) { - manager.ClientsLock.RLock() defer manager.ClientsLock.RUnlock() - for key, value := range manager.Clients { result := f(key, value) if result == false { return } } - return } -// GetClientsLen +// GetClientsLen GetClientsLen func (manager *ClientManager) GetClientsLen() (clientsLen int) { - clientsLen = len(manager.Clients) - return } -// 添加客户端 +// AddClients 添加客户端 func (manager *ClientManager) AddClients(client *Client) { manager.ClientsLock.Lock() defer manager.ClientsLock.Unlock() - manager.Clients[client] = true } -// 删除客户端 +// DelClients 删除客户端 func (manager *ClientManager) DelClients(client *Client) { manager.ClientsLock.Lock() defer manager.ClientsLock.Unlock() - if _, ok := manager.Clients[client]; ok { delete(manager.Clients, client) } } -// 获取用户的连接 -func (manager *ClientManager) GetUserClient(appId uint32, userId string) (client *Client) { - +// GetUserClient 获取用户的连接 +func (manager *ClientManager) GetUserClient(appID uint32, userID string) (client *Client) { manager.UserLock.RLock() defer manager.UserLock.RUnlock() - - userKey := GetUserKey(appId, userId) + userKey := GetUserKey(appID, userID) if value, ok := manager.Users[userKey]; ok { client = value } - return } -// GetClientsLen +// GetUsersLen GetClientsLen func (manager *ClientManager) GetUsersLen() (userLen int) { userLen = len(manager.Users) - return } -// 添加用户 +// AddUsers 添加用户 func (manager *ClientManager) AddUsers(key string, client *Client) { manager.UserLock.Lock() defer manager.UserLock.Unlock() - manager.Users[key] = client } -// 删除用户 +// DelUsers 删除用户 func (manager *ClientManager) DelUsers(client *Client) (result bool) { manager.UserLock.Lock() defer manager.UserLock.Unlock() - - key := GetUserKey(client.AppId, client.UserId) + key := GetUserKey(client.AppID, client.UserID) if value, ok := manager.Users[key]; ok { // 判断是否为相同的用户 if value.Addr != client.Addr { - return } delete(manager.Users, key) result = true } - return } -// 获取用户的key +// GetUserKeys 获取用户的key func (manager *ClientManager) GetUserKeys() (userKeys []string) { - - userKeys = make([]string, 0) - manager.UserLock.RLock() - defer manager.UserLock.RUnlock() + userKeys = make([]string, 0, len(manager.Users)) for key := range manager.Users { userKeys = append(userKeys, key) } - return } -// 获取用户的key -func (manager *ClientManager) GetUserList(appId uint32) (userList []string) { - +// GetUserList 获取用户 list +func (manager *ClientManager) GetUserList(appID uint32) (userList []string) { userList = make([]string, 0) - manager.UserLock.RLock() defer manager.UserLock.RUnlock() - for _, v := range manager.Users { - if v.AppId == appId { - userList = append(userList, v.UserId) + if v.AppID == appID { + userList = append(userList, v.UserID) } } - fmt.Println("GetUserList len:", len(manager.Users)) - return } -// 获取用户的key +// GetUserClients 获取用户的key func (manager *ClientManager) GetUserClients() (clients []*Client) { - clients = make([]*Client, 0) manager.UserLock.RLock() defer manager.UserLock.RUnlock() for _, v := range manager.Users { clients = append(clients, v) } - return } -// 向全部成员(除了自己)发送数据 +// sendAll 向全部成员(除了自己)发送数据 func (manager *ClientManager) sendAll(message []byte, ignoreClient *Client) { - clients := manager.GetUserClients() for _, conn := range clients { if conn != ignoreClient { @@ -220,43 +180,37 @@ func (manager *ClientManager) sendAll(message []byte, ignoreClient *Client) { } } -// 向全部成员(除了自己)发送数据 -func (manager *ClientManager) sendAppIdAll(message []byte, appId uint32, ignoreClient *Client) { - +// sendAppIDAll 向全部成员(除了自己)发送数据 +func (manager *ClientManager) sendAppIDAll(message []byte, appID uint32, ignoreClient *Client) { clients := manager.GetUserClients() for _, conn := range clients { - if conn != ignoreClient && conn.AppId == appId { + if conn != ignoreClient && conn.AppID == appID { conn.SendMsg(message) } } } -// 用户建立连接事件 +// EventRegister 用户建立连接事件 func (manager *ClientManager) EventRegister(client *Client) { manager.AddClients(client) - fmt.Println("EventRegister 用户建立连接", client.Addr) - // client.Send <- []byte("连接成功") } -// 用户登录 +// EventLogin 用户登录 func (manager *ClientManager) EventLogin(login *login) { - client := login.Client // 连接存在,在添加 if manager.InClient(client) { userKey := login.GetKey() manager.AddUsers(userKey, login.Client) } - - fmt.Println("EventLogin 用户登录", client.Addr, login.AppId, login.UserId) - - orderId := helper.GetOrderIdTime() - SendUserMessageAll(login.AppId, login.UserId, orderId, models.MessageCmdEnter, "哈喽~") + fmt.Println("EventLogin 用户登录", client.Addr, login.AppID, login.UserID) + orderID := helper.GetOrderIDTime() + _, _ = SendUserMessageAll(login.AppID, login.UserID, orderID, models.MessageCmdEnter, "哈喽~") } -// 用户断开连接 +// EventUnregister 用户断开连接 func (manager *ClientManager) EventUnregister(client *Client) { manager.DelClients(client) @@ -264,7 +218,6 @@ func (manager *ClientManager) EventUnregister(client *Client) { deleteResult := manager.DelUsers(client) if deleteResult == false { // 不是当前连接的客户端 - return } @@ -272,17 +225,15 @@ func (manager *ClientManager) EventUnregister(client *Client) { userOnline, err := cache.GetUserOnlineInfo(client.GetKey()) if err == nil { userOnline.LogOut() - cache.SetUserOnlineInfo(client.GetKey(), userOnline) + _ = cache.SetUserOnlineInfo(client.GetKey(), userOnline) } // 关闭 chan // close(client.Send) - - fmt.Println("EventUnregister 用户断开连接", client.Addr, client.AppId, client.UserId) - - if client.UserId != "" { - orderId := helper.GetOrderIdTime() - SendUserMessageAll(client.AppId, client.UserId, orderId, models.MessageCmdExit, "用户已经离开~") + fmt.Println("EventUnregister 用户断开连接", client.Addr, client.AppID, client.UserID) + if client.UserID != "" { + orderID := helper.GetOrderIDTime() + _, _ = SendUserMessageAll(client.AppID, client.UserID, orderID, models.MessageCmdExit, "用户已经离开~") } } @@ -293,15 +244,12 @@ func (manager *ClientManager) start() { case conn := <-manager.register: // 建立连接事件 manager.EventRegister(conn) - - case login := <-manager.login: + case l := <-manager.login: // 用户登录 - manager.EventLogin(login) - + manager.EventLogin(l) case conn := <-manager.unregister: // 断开连接事件 manager.EventUnregister(conn) - case message := <-manager.broadcast: // 广播事件 clients := manager.GetClients() @@ -316,69 +264,56 @@ func (manager *ClientManager) start() { } } -/************************** manager info ***************************************/ -// 获取管理者信息 +// GetManagerInfo 获取管理者信息 func GetManagerInfo(isDebug string) (managerInfo map[string]interface{}) { managerInfo = make(map[string]interface{}) - managerInfo["clientsLen"] = clientManager.GetClientsLen() // 客户端连接数 managerInfo["usersLen"] = clientManager.GetUsersLen() // 登录用户数 managerInfo["chanRegisterLen"] = len(clientManager.Register) // 未处理连接事件数 managerInfo["chanLoginLen"] = len(clientManager.Login) // 未处理登录事件数 managerInfo["chanUnregisterLen"] = len(clientManager.Unregister) // 未处理退出登录事件数 managerInfo["chanBroadcastLen"] = len(clientManager.Broadcast) // 未处理广播事件数 - if isDebug == "true" { addrList := make([]string, 0) clientManager.ClientsRange(func(client *Client, value bool) (result bool) { addrList = append(addrList, client.Addr) - return true }) - users := clientManager.GetUserKeys() - managerInfo["clients"] = addrList // 客户端列表 managerInfo["users"] = users // 登录用户列表 } - return } -// 获取用户所在的连接 -func GetUserClient(appId uint32, userId string) (client *Client) { - client = clientManager.GetUserClient(appId, userId) - +// GetUserClient 获取用户所在的连接 +func GetUserClient(appID uint32, userID string) (client *Client) { + client = clientManager.GetUserClient(appID, userID) return } -// 定时清理超时连接 +// ClearTimeoutConnections 定时清理超时连接 func ClearTimeoutConnections() { currentTime := uint64(time.Now().Unix()) - clients := clientManager.GetClients() for client := range clients { if client.IsHeartbeatTimeout(currentTime) { - fmt.Println("心跳时间超时 关闭连接", client.Addr, client.UserId, client.LoginTime, client.HeartbeatTime) - - client.Socket.Close() + fmt.Println("心跳时间超时 关闭连接", client.Addr, client.UserID, client.LoginTime, client.HeartbeatTime) + _ = client.Socket.Close() } } } -// 获取全部用户 -func GetUserList(appId uint32) (userList []string) { - fmt.Println("获取全部用户", appId) - - userList = clientManager.GetUserList(appId) - +// GetUserList 获取全部用户 +func GetUserList(appID uint32) (userList []string) { + fmt.Println("获取全部用户", appID) + userList = clientManager.GetUserList(appID) return } -// 全员广播 -func AllSendMessages(appId uint32, userId string, data string) { - fmt.Println("全员广播", appId, userId, data) - - ignoreClient := clientManager.GetUserClient(appId, userId) - clientManager.sendAppIdAll([]byte(data), appId, ignoreClient) +// AllSendMessages 全员广播 +func AllSendMessages(appID uint32, userID string, data string) { + fmt.Println("全员广播", appID, userID, data) + ignoreClient := clientManager.GetUserClient(appID, userID) + clientManager.sendAppIDAll([]byte(data), appID, ignoreClient) } diff --git a/servers/websocket/init_acc.go b/servers/websocket/init_acc.go index 2fd7d4d..8f99b38 100644 --- a/servers/websocket/init_acc.go +++ b/servers/websocket/init_acc.go @@ -1,10 +1,4 @@ -/** - * Created by GoLand. - * User: link1st - * Date: 2019-07-25 - * Time: 16:04 - */ - +// Package websocket 处理 package websocket import ( @@ -12,80 +6,72 @@ import ( "net/http" "time" - "gowebsocket/helper" - "gowebsocket/models" + "github.com/link1st/gowebsocket/v2/helper" + "github.com/link1st/gowebsocket/v2/models" "github.com/gorilla/websocket" "github.com/spf13/viper" ) const ( - defaultAppId = 101 // 默认平台Id + defaultAppID = 101 // 默认平台ID ) var ( clientManager = NewClientManager() // 管理者 - appIds = []uint32{defaultAppId, 102, 103, 104} // 全部的平台 - - serverIp string - serverPort string + appIDs = []uint32{defaultAppID, 102, 103, 104} // 全部的平台 + serverIp string + serverPort string ) -func GetAppIds() []uint32 { - - return appIds +// GetAppIDs 所有平台 +func GetAppIDs() []uint32 { + return appIDs } +// GetServer 获取服务器 func GetServer() (server *models.Server) { server = models.NewServer(serverIp, serverPort) - return } +// IsLocal 判断是否为本机 func IsLocal(server *models.Server) (isLocal bool) { if server.Ip == serverIp && server.Port == serverPort { isLocal = true } - return } -func InAppIds(appId uint32) (inAppId bool) { - - for _, value := range appIds { - if value == appId { - inAppId = true - +// InAppIDs in app +func InAppIDs(appID uint32) (inAppID bool) { + for _, value := range appIDs { + if value == appID { + inAppID = true return } } - return } -func GetDefaultAppId() (appId uint32) { - appId = defaultAppId - +// GetDefaultAppID 获取默认 appID +func GetDefaultAppID() (appID uint32) { + appID = defaultAppID return } -// 启动程序 +// StartWebSocket 启动程序 func StartWebSocket() { - serverIp = helper.GetServerIp() - webSocketPort := viper.GetString("app.webSocketPort") rpcPort := viper.GetString("app.rpcPort") - serverPort = rpcPort - http.HandleFunc("/acc", wsPage) // 添加处理程序 go clientManager.start() fmt.Println("WebSocket 启动程序成功", serverIp, serverPort) - - http.ListenAndServe(":"+webSocketPort, nil) + _ = http.ListenAndServe(":"+webSocketPort, nil) } func wsPage(w http.ResponseWriter, req *http.Request) { @@ -93,20 +79,15 @@ func wsPage(w http.ResponseWriter, req *http.Request) { // 升级协议 conn, err := (&websocket.Upgrader{CheckOrigin: func(r *http.Request) bool { fmt.Println("升级协议", "ua:", r.Header["User-Agent"], "referer:", r.Header["Referer"]) - return true }}).Upgrade(w, req, nil) if err != nil { http.NotFound(w, req) - return } - fmt.Println("webSocket 建立连接:", conn.RemoteAddr().String()) - currentTime := uint64(time.Now().Unix()) client := NewClient(conn.RemoteAddr().String(), conn, currentTime) - go client.read() go client.write() diff --git a/servers/websocket/user_srv.go b/servers/websocket/user_srv.go index de597fd..ad620f2 100644 --- a/servers/websocket/user_srv.go +++ b/servers/websocket/user_srv.go @@ -1,109 +1,89 @@ -/** -* Created by GoLand. -* User: link1st -* Date: 2019-07-30 -* Time: 12:27 - */ - +// Package websocket 处理 package websocket import ( "errors" "fmt" - "github.com/go-redis/redis" - "gowebsocket/lib/cache" - "gowebsocket/models" - "gowebsocket/servers/grpcclient" "time" -) -// 查询所有用户 -func UserList(appId uint32) (userList []string) { + "github.com/link1st/gowebsocket/v2/lib/cache" + "github.com/link1st/gowebsocket/v2/models" + "github.com/link1st/gowebsocket/v2/servers/grpcclient" + + "github.com/redis/go-redis/v9" +) +// UserList 查询所有用户 +func UserList(appID uint32) (userList []string) { userList = make([]string, 0) currentTime := uint64(time.Now().Unix()) servers, err := cache.GetServerAll(currentTime) if err != nil { fmt.Println("给全体用户发消息", err) - return } - for _, server := range servers { var ( list []string ) if IsLocal(server) { - list = GetUserList(appId) + list = GetUserList(appID) } else { - list, _ = grpcclient.GetUserList(server, appId) + list, _ = grpcclient.GetUserList(server, appID) } userList = append(userList, list...) } - return } -// 查询用户是否在线 -func CheckUserOnline(appId uint32, userId string) (online bool) { +// CheckUserOnline 查询用户是否在线 +func CheckUserOnline(appID uint32, userID string) (online bool) { // 全平台查询 - if appId == 0 { - for _, appId := range GetAppIds() { - online, _ = checkUserOnline(appId, userId) + if appID == 0 { + for _, appID := range GetAppIDs() { + online, _ = checkUserOnline(appID, userID) if online == true { break } } } else { - online, _ = checkUserOnline(appId, userId) + online, _ = checkUserOnline(appID, userID) } - return } -// 查询用户 是否在线 -func checkUserOnline(appId uint32, userId string) (online bool, err error) { - key := GetUserKey(appId, userId) +// checkUserOnline 查询用户 是否在线 +func checkUserOnline(appID uint32, userID string) (online bool, err error) { + key := GetUserKey(appID, userID) userOnline, err := cache.GetUserOnlineInfo(key) if err != nil { - if err == redis.Nil { - fmt.Println("GetUserOnlineInfo", appId, userId, err) - + if errors.Is(err, redis.Nil) { + fmt.Println("GetUserOnlineInfo", appID, userID, err) return false, nil } - - fmt.Println("GetUserOnlineInfo", appId, userId, err) - + fmt.Println("GetUserOnlineInfo", appID, userID, err) return } - online = userOnline.IsOnline() - return } -// 给用户发送消息 -func SendUserMessage(appId uint32, userId string, msgId, message string) (sendResults bool, err error) { - - data := models.GetTextMsgData(userId, msgId, message) - - client := GetUserClient(appId, userId) - +// SendUserMessage 给用户发送消息 +func SendUserMessage(appID uint32, userID string, msgID, message string) (sendResults bool, err error) { + data := models.GetTextMsgData(userID, msgID, message) + client := GetUserClient(appID, userID) if client != nil { // 在本机发送 - sendResults, err = SendUserMessageLocal(appId, userId, data) + sendResults, err = SendUserMessageLocal(appID, userID, data) if err != nil { - fmt.Println("给用户发送消息", appId, userId, err) + fmt.Println("给用户发送消息", appID, userID, err) } - return } - - key := GetUserKey(appId, userId) + key := GetUserKey(appID, userID) info, err := cache.GetUserOnlineInfo(key) if err != nil { fmt.Println("给用户发送消息失败", key, err) - return false, nil } if !info.IsOnline() { @@ -111,55 +91,46 @@ func SendUserMessage(appId uint32, userId string, msgId, message string) (sendRe return false, nil } server := models.NewServer(info.AccIp, info.AccPort) - msg, err := grpcclient.SendMsg(server, msgId, appId, userId, models.MessageCmdMsg, models.MessageCmdMsg, message) + msg, err := grpcclient.SendMsg(server, msgID, appID, userID, models.MessageCmdMsg, models.MessageCmdMsg, message) if err != nil { fmt.Println("给用户发送消息失败", key, err) - return false, err } fmt.Println("给用户发送消息成功-rpc", msg) sendResults = true - return } -// 给本机用户发送消息 -func SendUserMessageLocal(appId uint32, userId string, data string) (sendResults bool, err error) { - - client := GetUserClient(appId, userId) +// SendUserMessageLocal 给本机用户发送消息 +func SendUserMessageLocal(appID uint32, userID string, data string) (sendResults bool, err error) { + client := GetUserClient(appID, userID) if client == nil { err = errors.New("用户不在线") - return } // 发送消息 client.SendMsg([]byte(data)) sendResults = true - return } -// 给全体用户发消息 -func SendUserMessageAll(appId uint32, userId string, msgId, cmd, message string) (sendResults bool, err error) { +// SendUserMessageAll 给全体用户发消息 +func SendUserMessageAll(appID uint32, userID string, msgID, cmd, message string) (sendResults bool, err error) { sendResults = true - currentTime := uint64(time.Now().Unix()) servers, err := cache.GetServerAll(currentTime) if err != nil { fmt.Println("给全体用户发消息", err) - return } - for _, server := range servers { if IsLocal(server) { - data := models.GetMsgData(userId, msgId, cmd, message) - AllSendMessages(appId, userId, data) + data := models.GetMsgData(userID, msgID, cmd, message) + AllSendMessages(appID, userID, data) } else { - grpcclient.SendMsgAll(server, msgId, appId, userId, cmd, message) + _, _ = grpcclient.SendMsgAll(server, msgID, appID, userID, cmd, message) } } - return } diff --git a/views/home/index.html b/views/home/index.html index 2d6bc94..2f1147b 100644 --- a/views/home/index.html +++ b/views/home/index.html @@ -252,7 +252,7 @@ - + + type="text/javascript"> - appId = {{ .appId }}; + appID = {{ .appID }}; function currentTime() { let timeStamp = (new Date()).valueOf(); @@ -299,11 +299,11 @@ } - function sendId() { + function sendID() { let timeStamp = currentTime(); - let randId = randomNumber(100000, 999999); - let id = timeStamp + "-" + randId; + let randID = randomNumber(100000, 999999); + let id = timeStamp + "-" + randID; return id } @@ -368,13 +368,13 @@ // person = prompt("请输入你的名字", "hello-" + currentTime()); // if (person != null) { // console.log("用户准备登陆:" + person); - // ws.send('{"seq":"' + sendId() + '","cmd":"login","data":{"userId":"' + person + '","appId":'+ appId +'}}'); + // ws.send('{"seq":"' + sendID() + '","cmd":"login","data":{"userID":"' + person + '","appID":'+ appID +'}}'); // } person = getName(); // person = randomNumber(10000, 99999) console.log("用户准备登陆:" + person); - ws.send('{"seq":"' + sendId() + '","cmd":"login","data":{"userId":"' + person + '","appId":'+ appId +'}}'); + ws.send('{"seq":"' + sendID() + '","cmd":"login","data":{"userID":"' + person + '","appID":'+ appID +'}}'); // 定时心跳 setInterval(heartbeat, 30 * 1000) @@ -409,7 +409,7 @@ // 心跳 function heartbeat() { console.log("定时心跳:" + person); - ws.send('{"seq":"' + sendId() + '","cmd":"heartbeat","data":{}}'); + ws.send('{"seq":"' + sendID() + '","cmd":"heartbeat","data":{}}'); } @@ -434,9 +434,9 @@ type: "POST", url: 'http://{{ .httpUrl }}/user/sendMessageAll', data: { - appId: appId, - userId: person, - msgId: sendId(), + appID: appID, + userID: person, + msgID: sendID(), message: msg, }, contentType: "application/x-www-form-urlencoded", @@ -454,7 +454,7 @@ function getUserList() { $.ajax({ type: "GET", - url: "http://{{ .httpUrl }}/user/list?appId=" + appId, + url: "http://{{ .httpUrl }}/user/list?appID=" + appID, dataType: "json", success: function(data) { console.log("user list:" + data.code + "userList:" + data.data.userList);

AltStyle によって変換されたページ (->オリジナル) /