config增加心跳时间

This commit is contained in:
2025-09-09 13:35:22 +08:00
parent d90698401d
commit 3cc02d3a98
2 changed files with 8 additions and 6 deletions

View File

@@ -26,6 +26,8 @@ database:
websocket: websocket:
# WebSocket请求超时时间(秒) # WebSocket请求超时时间(秒)
timeout: 5 timeout: 5
# 心跳检测间隔(秒), 如果超过这个时间没有消息往来系统会自动发送一个心跳包维持长链接
heartbeat_interval: 54
# 心跳配置 # 心跳配置
heartbeat: heartbeat:

View File

@@ -77,6 +77,9 @@ type DatabaseConfig struct {
type WebSocketConfig struct { type WebSocketConfig struct {
// Timeout WebSocket请求超时时间(秒) // Timeout WebSocket请求超时时间(秒)
Timeout int `yaml:"timeout"` Timeout int `yaml:"timeout"`
// HeartbeatInterval 心跳检测间隔(秒), 如果超过这个时间没有消息往来系统会自动发送一个心跳包维持长链接
HeartbeatInterval int `yaml:"heartbeat_interval"`
} }
// HeartbeatConfig 代表心跳配置 // HeartbeatConfig 代表心跳配置
@@ -130,12 +133,9 @@ func (c *Config) GetDatabaseConnectionString() string {
) )
} }
// GetWebSocketTimeout 获取WebSocket超时时间(秒) // GetWebSocketConfig 获取WebSocket配置
func (c *Config) GetWebSocketTimeout() int { func (c *Config) GetWebSocketConfig() WebSocketConfig {
if c.WebSocket.Timeout <= 0 { return c.WebSocket
return 5 // 默认5秒超时
}
return c.WebSocket.Timeout
} }
// GetHeartbeatConfig 获取心跳配置 // GetHeartbeatConfig 获取心跳配置