可配置是否存储连接

This commit is contained in:
白茶清欢 2021-04-17 23:14:54 +08:00
parent 563c334757
commit 3548b434d0
2 changed files with 16 additions and 2 deletions

View File

@ -38,6 +38,8 @@ const (
DefaultLogLevel = zapcore.DebugLevel DefaultLogLevel = zapcore.DebugLevel
// DefaultLogSplitInterval 默认的日志切割时间 // DefaultLogSplitInterval 默认的日志切割时间
DefaultLogSplitInterval = logger.TimeIntervalTypeHour DefaultLogSplitInterval = logger.TimeIntervalTypeHour
// DefaultStoreConnection 默认存储连接
DefaultStoreConnection = true
) )
// WSServerConfig WS-Server的配置 // WSServerConfig WS-Server的配置
@ -53,6 +55,7 @@ type WSServerConfig struct {
LogFile string // 日志文件名 LogFile string // 日志文件名
LogLevel zapcore.Level // 日志等级 LogLevel zapcore.Level // 日志等级
LogSplitInterval logger.TimeIntervalType // 日至切割的时间间隔 LogSplitInterval logger.TimeIntervalType // 日至切割的时间间隔
StoreConnection bool // 存储连接
} }
// SetWSServerConfig 设置WS-Server的配置 // SetWSServerConfig 设置WS-Server的配置
@ -85,6 +88,17 @@ func SetWSServerLogEnable(logPath string, logFile string, logLevel zapcore.Level
} }
} }
// DisableStoreConnection 禁用连接存储
//
// Author : go_developer@163.com<张德满>
//
// Date : 11:10 下午 2021/4/17
func DisableStoreConnection() SetWSServerConfig {
return func(wsc *WSServerConfig) {
wsc.StoreConnection = true
}
}
// NewWSServerConfig 生成新的WS-Server配置 // NewWSServerConfig 生成新的WS-Server配置
// //
// Author : go_developer@163.com<张德满> // Author : go_developer@163.com<张德满>

View File

@ -137,7 +137,7 @@ func NewWebsocketServe(wsInstanceList ...abstract.IWebsocket) error {
ctx := ctxInterface.(*context.WSContext) ctx := ctxInterface.(*context.WSContext)
ctx.Session = session ctx.Session = session
if err := wsInstance.Connect(ctx); nil == err { if err := wsInstance.Connect(ctx); nil == err {
if nil != storage.Connection { if ginRouterTable[wsInstance.GetServerPort()].conf.StoreConnection && nil != storage.Connection {
storage.Connection.Store(ctx) storage.Connection.Store(ctx)
} }
} }
@ -154,7 +154,7 @@ func NewWebsocketServe(wsInstanceList ...abstract.IWebsocket) error {
ctxInterface, _ := session.Get("ws_context") ctxInterface, _ := session.Get("ws_context")
ctx := ctxInterface.(*context.WSContext) ctx := ctxInterface.(*context.WSContext)
defer func() { defer func() {
if nil == storage.Connection { if !ginRouterTable[wsInstance.GetServerPort()].conf.StoreConnection || nil == storage.Connection {
return return
} }
storage.Connection.Del(ctx) storage.Connection.Del(ctx)