From 3cc02d3a98ef89b7adb9695ef3b2970185ca8240 Mon Sep 17 00:00:00 2001 From: huang <1724659546@qq.com> Date: Tue, 9 Sep 2025 13:35:22 +0800 Subject: [PATCH] =?UTF-8?q?config=E5=A2=9E=E5=8A=A0=E5=BF=83=E8=B7=B3?= =?UTF-8?q?=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.yml | 2 ++ internal/config/config.go | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/config.yml b/config.yml index ad8f8ab..dd313bf 100644 --- a/config.yml +++ b/config.yml @@ -26,6 +26,8 @@ database: websocket: # WebSocket请求超时时间(秒) timeout: 5 + # 心跳检测间隔(秒), 如果超过这个时间没有消息往来系统会自动发送一个心跳包维持长链接 + heartbeat_interval: 54 # 心跳配置 heartbeat: diff --git a/internal/config/config.go b/internal/config/config.go index ca8e74a..0444a90 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -77,6 +77,9 @@ type DatabaseConfig struct { type WebSocketConfig struct { // Timeout WebSocket请求超时时间(秒) Timeout int `yaml:"timeout"` + + // HeartbeatInterval 心跳检测间隔(秒), 如果超过这个时间没有消息往来系统会自动发送一个心跳包维持长链接 + HeartbeatInterval int `yaml:"heartbeat_interval"` } // HeartbeatConfig 代表心跳配置 @@ -130,12 +133,9 @@ func (c *Config) GetDatabaseConnectionString() string { ) } -// GetWebSocketTimeout 获取WebSocket超时时间(秒) -func (c *Config) GetWebSocketTimeout() int { - if c.WebSocket.Timeout <= 0 { - return 5 // 默认5秒超时 - } - return c.WebSocket.Timeout +// GetWebSocketConfig 获取WebSocket配置 +func (c *Config) GetWebSocketConfig() WebSocketConfig { + return c.WebSocket } // GetHeartbeatConfig 获取心跳配置