diff --git a/config/server.go b/config/server.go index 1d1b917..14d2ba3 100644 --- a/config/server.go +++ b/config/server.go @@ -9,6 +9,7 @@ package config import ( "github.com/go-developer/gopkg/logger" + "github.com/go-developer/websocket/storage" "go.uber.org/zap/zapcore" ) @@ -48,14 +49,15 @@ const ( // // Date : 7:02 下午 2021/4/17 type WSServerConfig struct { - Mode string // 运行模式 - LogEnable bool // 开启日志 - LogConsole bool // 开启控制台日志输出 - LogPath string // 日志路径 - LogFile string // 日志文件名 - LogLevel zapcore.Level // 日志等级 - LogSplitInterval logger.TimeIntervalType // 日至切割的时间间隔 - StoreConnection bool // 存储连接 + Mode string // 运行模式 + LogEnable bool // 开启日志 + LogConsole bool // 开启控制台日志输出 + LogPath string // 日志路径 + LogFile string // 日志文件名 + LogLevel zapcore.Level // 日志等级 + LogSplitInterval logger.TimeIntervalType // 日至切割的时间间隔 + StoreConnection bool // 存储连接 + ConnectionManager storage.IConnection // 连接管理实例 } // SetWSServerConfig 设置WS-Server的配置 @@ -110,13 +112,14 @@ func DisableStoreConnection() SetWSServerConfig { // Date : 7:21 下午 2021/4/17 func NewWSServerConfig(optionList ...SetWSServerConfig) *WSServerConfig { c := &WSServerConfig{ - Mode: DefaultMode, - LogEnable: DefaultLogEnable, - LogConsole: DefaultLogConsole, - LogPath: "", - LogLevel: DefaultLogLevel, - LogSplitInterval: DefaultLogSplitInterval, - StoreConnection: DefaultStoreConnection, + Mode: DefaultMode, + LogEnable: DefaultLogEnable, + LogConsole: DefaultLogConsole, + LogPath: "", + LogLevel: DefaultLogLevel, + LogSplitInterval: DefaultLogSplitInterval, + StoreConnection: DefaultStoreConnection, + ConnectionManager: storage.NewDefaultConnectionManager(), } for _, o := range optionList { o(c) diff --git a/storage/connection.go b/storage/connection.go index c504fdb..6fe7bc5 100644 --- a/storage/connection.go +++ b/storage/connection.go @@ -12,15 +12,15 @@ import ( "github.com/go-developer/websocket/context" ) -var ( - // Connection 连接管理 - Connection IConnection -) - -func init() { +// NewDefaultConnectionManager 默认的内存连接管理实例 +// +// Author : go_developer@163.com<张德满> +// +// Date : 11:32 下午 2021/4/17 +func NewDefaultConnectionManager() IConnection { c := &connection{} c.table, _ = easymap.NewSegment(4096, true) - Connection = c + return c } type connection struct {