代码规范过滤,移除冗余代码,替换掉不推荐的包

This commit is contained in:
孟帅
2023-05-30 12:09:40 +08:00
parent c8a808fcfd
commit b2ef3487d3
74 changed files with 564 additions and 741 deletions

View File

@@ -3,7 +3,6 @@
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
//
package websocket
import (
@@ -105,7 +104,7 @@ func (c *Client) write() {
}()
defer func() {
clientManager.Unregister <- c
c.Socket.Close()
_ = c.Socket.Close()
}()
for {
select {
@@ -118,7 +117,7 @@ func (c *Client) write() {
g.Log().Warningf(ctxManager, "client write message, user:%+v", c.User)
return
}
c.Socket.WriteJSON(message)
_ = c.Socket.WriteJSON(message)
}
}
}
@@ -147,7 +146,6 @@ func (c *Client) Context() context.Context {
// Heartbeat 心跳更新
func (c *Client) Heartbeat(currentTime uint64) {
c.HeartbeatTime = currentTime
return
}
// IsHeartbeatTimeout 心跳是否超时

View File

@@ -3,7 +3,6 @@
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
//
package websocket
import (
@@ -79,12 +78,10 @@ func (manager *ClientManager) ClientsRange(f func(client *Client, value bool) (r
manager.ClientsLock.RLock()
defer manager.ClientsLock.RUnlock()
for key, value := range manager.Clients {
result := f(key, value)
if result == false {
if !f(key, value) {
return
}
}
return
}
// GetClientsLen 获取客户端总数
@@ -104,14 +101,12 @@ func (manager *ClientManager) AddClients(client *Client) {
func (manager *ClientManager) DelClients(client *Client) {
manager.ClientsLock.Lock()
defer manager.ClientsLock.Unlock()
if _, ok := manager.Clients[client]; ok {
delete(manager.Clients, client)
}
delete(manager.Clients, client)
}
// GetClient 通过socket ID获取客户端的连接
func (manager *ClientManager) GetClient(ID string) (client *Client) {
for c, _ := range manager.Clients {
for c := range manager.Clients {
if c.ID == ID {
return c
}
@@ -187,7 +182,7 @@ func (manager *ClientManager) EventUnregister(client *Client) {
manager.DelClients(client)
// 删除用户连接
deleteResult := manager.DelUsers(client)
if deleteResult == false {
if !deleteResult {
// 不是当前连接的客户端
return
}
@@ -202,7 +197,7 @@ func (manager *ClientManager) clearTimeoutConnections() {
for client := range clients {
if client.IsHeartbeatTimeout(currentTime) {
//fmt.Println("心跳时间超时 关闭连接", client.Addr, client.UserId, client.LoginTime, client.HeartbeatTime)
client.Socket.Close()
_ = client.Socket.Close()
}
}
}
@@ -224,7 +219,7 @@ func (manager *ClientManager) ping() {
// SendToAll(res)
//})
// 定时任务,清理超时连接
gcron.Add(ctxManager, "*/30 * * * * *", func(ctx context.Context) {
_, _ = gcron.Add(ctxManager, "*/30 * * * * *", func(ctx context.Context) {
manager.clearTimeoutConnections()
})
}