增加事件

This commit is contained in:
ideaa
2025-05-19 10:03:05 +08:00
parent 8d75fd8901
commit eb04ace652
3 changed files with 8 additions and 2 deletions

7
app.go
View File

@@ -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
}

View File

@@ -25,7 +25,6 @@ func NewServer(engine http.Handler) *Server {
InitManager()
wss = &Server{
engine: engine,
port: ":3322",
fn: HttpHandler,
}
})

View File

@@ -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
}