49 lines
1.2 KiB
Go
49 lines
1.2 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 string `yaml:"mysql_dsn"`
|
|
MySQLAutoMigrate bool `yaml:"mysql_auto_migrate"`
|
|
Ledger LedgerConfig `yaml:"ledger"`
|
|
}
|
|
|
|
// LedgerConfig 保存账务底座配置。
|
|
type LedgerConfig struct {
|
|
Currency string `yaml:"currency"`
|
|
IdempotencyTTLSec int64 `yaml:"idempotency_ttl_sec"`
|
|
}
|
|
|
|
// Default 返回本地开发默认配置。
|
|
func Default() Config {
|
|
return Config{
|
|
ServiceName: "wallet-service",
|
|
NodeID: "wallet-local",
|
|
GRPCAddr: ":13004",
|
|
MySQLDSN: "",
|
|
MySQLAutoMigrate: false,
|
|
Ledger: LedgerConfig{
|
|
Currency: "coin",
|
|
IdempotencyTTLSec: 86400,
|
|
},
|
|
}
|
|
}
|
|
|
|
// 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
|
|
}
|