58 lines
1.7 KiB
Go
58 lines
1.7 KiB
Go
package config
|
||
|
||
import (
|
||
"time"
|
||
|
||
"hyapp/pkg/configx"
|
||
)
|
||
|
||
// Config 描述 gateway-service 启动所需的最小配置。
|
||
type Config struct {
|
||
HTTPAddr string `yaml:"http_addr"`
|
||
JWTSecret string `yaml:"jwt_secret"`
|
||
RoomServiceAddr string `yaml:"room_service_addr"`
|
||
UserServiceAddr string `yaml:"user_service_addr"`
|
||
TencentIM TencentIMConfig `yaml:"tencent_im"`
|
||
}
|
||
|
||
// TencentIMConfig 描述 gateway 给客户端签发腾讯云 IM UserSig 的配置。
|
||
type TencentIMConfig struct {
|
||
// SDKAppID 是腾讯云 IM 控制台分配的应用 ID。
|
||
SDKAppID int64 `yaml:"sdk_app_id"`
|
||
// SecretKey 只允许出现在服务端配置中,不能下发给客户端。
|
||
SecretKey string `yaml:"secret_key"`
|
||
// UserSigTTL 是客户端 IM 登录票据有效期。
|
||
UserSigTTL time.Duration `yaml:"user_sig_ttl"`
|
||
// CallbackURL 是在腾讯云 IM 控制台配置的服务端回调地址。
|
||
CallbackURL string `yaml:"callback_url"`
|
||
// CallbackAuthToken 是腾讯云 IM 回调鉴权 token,只用于校验回调来源。
|
||
CallbackAuthToken string `yaml:"callback_auth_token"`
|
||
}
|
||
|
||
// Default 返回本地开发默认配置。
|
||
func Default() Config {
|
||
return Config{
|
||
HTTPAddr: ":13000",
|
||
JWTSecret: "gateway-dev-secret",
|
||
RoomServiceAddr: "127.0.0.1:13001",
|
||
UserServiceAddr: "127.0.0.1:13005",
|
||
TencentIM: TencentIMConfig{
|
||
UserSigTTL: 24 * time.Hour,
|
||
},
|
||
}
|
||
}
|
||
|
||
// Load 从独立 config.yaml 读取 gateway-service 配置。
|
||
func Load(path string) (Config, error) {
|
||
cfg := Default()
|
||
if path == "" {
|
||
return cfg, nil
|
||
}
|
||
|
||
if err := configx.LoadYAML(path, &cfg); err != nil {
|
||
return Config{}, err
|
||
}
|
||
|
||
return cfg, nil
|
||
}
|