1、泛型化参数,预留泛型约束,方便以后代码扩展的类型安全校验

2、升级goframe至v2.7.3
This commit is contained in:
apefuu
2024-09-19 19:33:00 +08:00
parent 2a87055b62
commit f18ce6384b
57 changed files with 221 additions and 220 deletions

View File

@@ -55,7 +55,7 @@ type Client struct {
}
// NewClient 初始化
func NewClient(r *ghttp.Request, socket *websocket.Conn, firstTime uint64) (client *Client) {
func NewClient[T any](r *ghttp.Request, socket *websocket.Conn, firstTime uint64) (client *Client) {
client = &Client{
Addr: socket.RemoteAddr().String(),
ID: guid.S(),
@@ -65,7 +65,7 @@ func NewClient(r *ghttp.Request, socket *websocket.Conn, firstTime uint64) (clie
closeSignal: make(chan struct{}, 1),
FirstTime: firstTime,
HeartbeatTime: firstTime,
User: contexts.GetUser(r.Context()),
User: contexts.GetUser[T](r.Context()),
IP: location.GetClientIp(r),
UserAgent: r.UserAgent(),
}

View File

@@ -35,7 +35,7 @@ func Stop() {
}
// WsPage ws入口
func WsPage(r *ghttp.Request) {
func WsPage[T any](r *ghttp.Request) {
upGrader := websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
@@ -48,7 +48,7 @@ func WsPage(r *ghttp.Request) {
return
}
currentTime := uint64(gtime.Now().Unix())
client := NewClient(r, conn, currentTime)
client := NewClient[T](r, conn, currentTime)
go client.read()
go client.write()
// 用户连接事件