增加事件

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 ( import (
"fmt" "fmt"
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
@@ -15,6 +16,7 @@ import (
"github.com/wonli/aqi/internal/config" "github.com/wonli/aqi/internal/config"
"github.com/wonli/aqi/logger" "github.com/wonli/aqi/logger"
"github.com/wonli/aqi/validate" "github.com/wonli/aqi/validate"
"github.com/wonli/aqi/ws"
) )
type AppConfig struct { type AppConfig struct {
@@ -106,7 +108,7 @@ func Init(options ...Option) *AppConfig {
os.Exit(1) os.Exit(1)
} }
color.Red("failed to read config file: %s", err.Error()) color.Red("failed to read config file")
os.Exit(1) os.Exit(1)
} }
@@ -205,5 +207,8 @@ func Init(options ...Option) *AppConfig {
//监听配置 //监听配置
viper.WatchConfig() viper.WatchConfig()
//初始化hub
ws.InitManager()
return acf return acf
} }

View File

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

View File

@@ -94,6 +94,7 @@ func (u *User) appLogin(appId string, client *Client) error {
u.AppClients = append(u.AppClients, client) u.AppClients = append(u.AppClients, client)
} }
u.Hub.PubSub.Pub("login", u)
return nil return nil
} }
@@ -115,6 +116,7 @@ func (u *User) appLogout(appId string, logoutClient *Client) error {
logoutClient.Close() logoutClient.Close()
} }
u.Hub.PubSub.Pub("logout", u)
return nil return nil
} }