From 3548b434d01706c2d5bb3291c003a87751ffa4a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=BE=B7=E6=BB=A1?= Date: Sat, 17 Apr 2021 23:14:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AF=E9=85=8D=E7=BD=AE=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E8=BF=9E=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/server.go | 14 ++++++++++++++ construct.go | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/config/server.go b/config/server.go index f440df2..e9d925f 100644 --- a/config/server.go +++ b/config/server.go @@ -38,6 +38,8 @@ const ( DefaultLogLevel = zapcore.DebugLevel // DefaultLogSplitInterval 默认的日志切割时间 DefaultLogSplitInterval = logger.TimeIntervalTypeHour + // DefaultStoreConnection 默认存储连接 + DefaultStoreConnection = true ) // WSServerConfig WS-Server的配置 @@ -53,6 +55,7 @@ type WSServerConfig struct { LogFile string // 日志文件名 LogLevel zapcore.Level // 日志等级 LogSplitInterval logger.TimeIntervalType // 日至切割的时间间隔 + StoreConnection bool // 存储连接 } // 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配置 // // Author : go_developer@163.com<张德满> diff --git a/construct.go b/construct.go index a007d83..0afeb07 100644 --- a/construct.go +++ b/construct.go @@ -137,7 +137,7 @@ func NewWebsocketServe(wsInstanceList ...abstract.IWebsocket) error { ctx := ctxInterface.(*context.WSContext) ctx.Session = session if err := wsInstance.Connect(ctx); nil == err { - if nil != storage.Connection { + if ginRouterTable[wsInstance.GetServerPort()].conf.StoreConnection && nil != storage.Connection { storage.Connection.Store(ctx) } } @@ -154,7 +154,7 @@ func NewWebsocketServe(wsInstanceList ...abstract.IWebsocket) error { ctxInterface, _ := session.Get("ws_context") ctx := ctxInterface.(*context.WSContext) defer func() { - if nil == storage.Connection { + if !ginRouterTable[wsInstance.GetServerPort()].conf.StoreConnection || nil == storage.Connection { return } storage.Connection.Del(ctx)