mirror of
https://github.com/wonli/aqi.git
synced 2025-09-26 20:51:23 +08:00
增加事件
This commit is contained in:
7
app.go
7
app.go
@@ -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
|
||||||
}
|
}
|
||||||
|
@@ -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,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user