40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package config
|
|
|
|
import "hyapp/pkg/configx"
|
|
|
|
// Config 描述 wallet-service 启动配置。
|
|
type Config struct {
|
|
ServiceName string `yaml:"service_name"`
|
|
NodeID string `yaml:"node_id"`
|
|
GRPCAddr string `yaml:"grpc_addr"`
|
|
// MySQLDSN 是账户、交易、分录和 outbox 的必需存储连接串。
|
|
MySQLDSN string `yaml:"mysql_dsn"`
|
|
// MySQLAutoMigrate 保留给显式本地迁移;线上 schema 由发布流程或 initdb 管理。
|
|
MySQLAutoMigrate bool `yaml:"mysql_auto_migrate"`
|
|
}
|
|
|
|
// Default 返回本地开发默认配置。
|
|
func Default() Config {
|
|
return Config{
|
|
ServiceName: "wallet-service",
|
|
NodeID: "wallet-local",
|
|
GRPCAddr: ":13004",
|
|
MySQLDSN: "hyapp:hyapp@tcp(127.0.0.1:23306)/hyapp_wallet?parseTime=true&charset=utf8mb4&loc=Local",
|
|
MySQLAutoMigrate: false,
|
|
}
|
|
}
|
|
|
|
// Load 从独立 config.yaml 读取 wallet-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
|
|
}
|