From eb04ace652afb099fe3f75ba13fb8e0e6d156a21 Mon Sep 17 00:00:00 2001 From: ideaa Date: Mon, 19 May 2025 10:03:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.go | 7 ++++++- ws/server.go | 1 - ws/user.go | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app.go b/app.go index d2233ff..873bcfb 100644 --- a/app.go +++ b/app.go @@ -2,6 +2,7 @@ package aqi import ( "fmt" + "net/http" "os" "path/filepath" @@ -15,6 +16,7 @@ import ( "github.com/wonli/aqi/internal/config" "github.com/wonli/aqi/logger" "github.com/wonli/aqi/validate" + "github.com/wonli/aqi/ws" ) type AppConfig struct { @@ -106,7 +108,7 @@ func Init(options ...Option) *AppConfig { os.Exit(1) } - color.Red("failed to read config file: %s", err.Error()) + color.Red("failed to read config file") os.Exit(1) } @@ -205,5 +207,8 @@ func Init(options ...Option) *AppConfig { //监听配置 viper.WatchConfig() + + //初始化hub + ws.InitManager() return acf } diff --git a/ws/server.go b/ws/server.go index 8eb02da..380257e 100644 --- a/ws/server.go +++ b/ws/server.go @@ -25,7 +25,6 @@ func NewServer(engine http.Handler) *Server { InitManager() wss = &Server{ engine: engine, - port: ":3322", fn: HttpHandler, } }) diff --git a/ws/user.go b/ws/user.go index 45f32ce..87300a2 100644 --- a/ws/user.go +++ b/ws/user.go @@ -94,6 +94,7 @@ func (u *User) appLogin(appId string, client *Client) error { u.AppClients = append(u.AppClients, client) } + u.Hub.PubSub.Pub("login", u) return nil } @@ -115,6 +116,7 @@ func (u *User) appLogout(appId string, logoutClient *Client) error { logoutClient.Close() } + u.Hub.PubSub.Pub("logout", u) return nil }