49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package config
|
|
|
|
import "hyapp/pkg/configx"
|
|
|
|
// Config 描述 activity-service 启动配置。
|
|
type Config struct {
|
|
ServiceName string `yaml:"service_name"`
|
|
NodeID string `yaml:"node_id"`
|
|
GRPCAddr string `yaml:"grpc_addr"`
|
|
MySQLDSN string `yaml:"mysql_dsn"`
|
|
MySQLAutoMigrate bool `yaml:"mysql_auto_migrate"`
|
|
Consumer ConsumerConfig `yaml:"consumer"`
|
|
}
|
|
|
|
// ConsumerConfig 保存 room outbox 消费底座配置。
|
|
type ConsumerConfig struct {
|
|
RoomOutboxPollIntervalMs int64 `yaml:"room_outbox_poll_interval_ms"`
|
|
BatchSize int `yaml:"batch_size"`
|
|
}
|
|
|
|
// Default 返回本地默认配置。
|
|
func Default() Config {
|
|
return Config{
|
|
ServiceName: "activity-service",
|
|
NodeID: "activity-local",
|
|
GRPCAddr: ":13006",
|
|
MySQLDSN: "",
|
|
MySQLAutoMigrate: false,
|
|
Consumer: ConsumerConfig{
|
|
RoomOutboxPollIntervalMs: 1000,
|
|
BatchSize: 100,
|
|
},
|
|
}
|
|
}
|
|
|
|
// Load 从独立 config.yaml 读取 activity-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
|
|
}
|