package setting // ServerSettingS 服务配置。时间字段单位为秒(int),避免 time.Duration 对整数配置按纳秒解析的歧义。 type ServerSettingS struct { Domain string // 服务域名(用于 CORS 允许来源,如 test.com) RunMode string HttpPort string ReadTimeout int // 秒 WriteTimeout int // 秒 } type LogSettingS struct { LogSavePath string LogFileName string LogFileExt string MaxSize int MaxBackups int MaxAge int LogLevel string } type MysqlSettingS struct { UserName string Password string Host string Port int DBName string MaxIdleConns int MaxOpenConns int ConnMaxLifeTime int ConnMaxIdleTime int } type RedisSettingS struct { Host string Port int Password string DB int PoolSize int MaxIdleConns int MinIdleConns int MaxRetryBackoff int MinRetryBackoff int MaxRetries int DialTimeout int ReadTimeout int WriteTimeout int PoolTimeout int } type JWTSettingS struct { SecretKey string Issuer string AccessTokenExpire int // 秒 RefreshTokenExpire int // 秒 } type UploadSettingS struct { TmpSavePath string MaxSizeMB int AllowedExtensions []string } type CosSettingS struct { CosSecretID string CosSecretKey string CosUploadDomain string CosDownloadDomain string CdnDownloadSecretKey string } // WechatMiniSettingS 微信小程序配置(用于 code2session 登录)。 type WechatMiniSettingS struct { AppID string AppSecret string } // WSSettingS WebSocket 网关配置。 // 前半段供 internal/wsgateway 传输层使用;后半段是第二步房间与匹配要用的预留项。 type WSSettingS struct { PingInterval int // 心跳间隔(秒):服务端按此周期发 ping,也下发给客户端作为应用层心跳建议值 ReadTimeout int // 读超时(秒):超过该时长未收到任何客户端消息即判定死连接并断开 WriteTimeout int // 写超时(秒):单次 Write 或 Ping 的最长等待时间 MaxMessageBytes int // 单帧上限(字节):超过该大小的消息由库直接拒绝 MaxMsgPerSec int // 单连接每秒消息数上限:用于限流,超出即断开 SendQueueSize int // 发送队列长度:写满说明客户端消费太慢(慢客户端),直接断开 Compression bool // 是否启用 permessage-deflate 压缩 MultiDevice bool // 是否允许多设备同时在线:false 表示同账号新连接踢掉旧连接 OriginPatterns []string // 允许的 Origin 域名列表:浏览器调试用,小游戏连接通常不带 Origin // ===== 以下为房间 / 匹配预留(第二步填充) ===== ReconnectGraceSec int // 掉线后保留座位的时长(秒):超时未重连则判负或平局 RoomIdleTimeoutSec int // 房间空闲自动关闭的时长(秒) MatchTimeoutSec int // 匹配排队超过该时长(秒)自动取消 QueueTickMs int // 匹配队列的扫描间隔(毫秒) MaxRooms int // 同时存在的房间数上限,防止内存失控 AIEnabled bool // 匹配超时后是否用 AI 补齐空位(对外不可感知) AIWaitSec int // 排队超过该秒数仍未凑满则补 AI;0 表示不启用 } func (s *Setting) ReadSection(k string, v any) error { err := s.vp.UnmarshalKey(k, v) if err != nil { return err } return nil }