110 lines
3.6 KiB
Go
110 lines
3.6 KiB
Go
package config
|
||
|
||
import (
|
||
"flag"
|
||
"log"
|
||
)
|
||
|
||
// GalleryRulesConfig 展馆规则配置(硬编码)
|
||
type GalleryRulesConfig struct {
|
||
// 初始展位数(默认:3)
|
||
InitialSlotCount int
|
||
|
||
// 抢展位时长(秒,默认:14400,即4小时)
|
||
GrabSlotDuration int64
|
||
|
||
// 按等级解锁成本(slot_index -> level)
|
||
// 例如:第4个展位需要等级5,第5个展位需要等级6
|
||
UnlockLevelBySlot map[int]int
|
||
|
||
// 按水晶解锁成本(slot_index -> crystal_cost)
|
||
// 例如:第4个展位需要水晶100,第5个展位需要水晶200
|
||
UnlockCrystalBySlot map[int]int
|
||
|
||
// 最大展位数(默认:10)
|
||
MaxSlotCount int
|
||
}
|
||
|
||
// DatabaseConfig 数据库配置
|
||
type DatabaseConfig struct {
|
||
Host string
|
||
Port int
|
||
User string
|
||
Password string
|
||
DBName string
|
||
SSLMode string
|
||
}
|
||
|
||
// ServiceURLs RPC服务地址配置
|
||
type ServiceURLs struct {
|
||
AssetService string
|
||
UserService string
|
||
TaskService string
|
||
}
|
||
|
||
var (
|
||
// GalleryRules 展馆规则配置(硬编码)
|
||
GalleryRules = &GalleryRulesConfig{
|
||
InitialSlotCount: 6, // 3 个公开 + 3 个私有
|
||
GrabSlotDuration: 14400, // 4小时
|
||
|
||
// 按等级解锁:第4个展位需要等级5,第5个展位需要等级6,以此类推
|
||
UnlockLevelBySlot: map[int]int{
|
||
4: 5, // 第4个展位需要等级5
|
||
5: 6, // 第5个展位需要等级6
|
||
6: 7, // 第6个展位需要等级7
|
||
7: 8, // 第7个展位需要等级8
|
||
8: 9, // 第8个展位需要等级9
|
||
9: 10, // 第9个展位需要等级10
|
||
10: 11, // 第10个展位需要等级11
|
||
},
|
||
|
||
// 按水晶解锁:第4个展位需要水晶100,第5个展位需要水晶200,以此类推
|
||
UnlockCrystalBySlot: map[int]int{
|
||
4: 100, // 第4个展位需要水晶100
|
||
5: 200, // 第5个展位需要水晶200
|
||
6: 300, // 第6个展位需要水晶300
|
||
7: 400, // 第7个展位需要水晶400
|
||
8: 500, // 第8个展位需要水晶500
|
||
9: 600, // 第9个展位需要水晶600
|
||
10: 700, // 第10个展位需要水晶700
|
||
},
|
||
|
||
MaxSlotCount: 10,
|
||
}
|
||
|
||
// DBConfig 数据库配置(由 main.go 的 flag 或环境变量注入)
|
||
DBConfig = &DatabaseConfig{}
|
||
|
||
// ServiceURLsConfig RPC服务地址配置(由 main.go 的 flag 或环境变量注入)
|
||
ServiceURLsConfig = &ServiceURLs{
|
||
AssetService: "tri://localhost:20003",
|
||
UserService: "tri://localhost:20000",
|
||
TaskService: "tri://localhost:20004",
|
||
}
|
||
)
|
||
|
||
// InitConfig 从命令行参数初始化配置
|
||
func InitConfig() {
|
||
// 数据库配置
|
||
flag.StringVar(&DBConfig.Host, "db-host", "localhost", "数据库主机地址")
|
||
flag.IntVar(&DBConfig.Port, "db-port", 5432, "数据库端口")
|
||
flag.StringVar(&DBConfig.User, "db-user", "postgres", "数据库用户名")
|
||
flag.StringVar(&DBConfig.Password, "db-password", "", "数据库密码")
|
||
flag.StringVar(&DBConfig.DBName, "db-name", "topfans", "数据库名称")
|
||
flag.StringVar(&DBConfig.SSLMode, "db-sslmode", "disable", "数据库SSL模式")
|
||
|
||
// RPC服务地址配置
|
||
flag.StringVar(&ServiceURLsConfig.AssetService, "asset-service-url", "tri://localhost:20003", "Asset Service RPC地址")
|
||
flag.StringVar(&ServiceURLsConfig.UserService, "user-service-url", "tri://localhost:20000", "User Service RPC地址")
|
||
flag.StringVar(&ServiceURLsConfig.TaskService, "task-service-url", "tri://localhost:20004", "Task Service RPC地址")
|
||
|
||
flag.Parse()
|
||
|
||
log.Println("配置初始化完成:")
|
||
log.Printf(" 数据库: %s:%d/%s", DBConfig.Host, DBConfig.Port, DBConfig.DBName)
|
||
log.Printf(" Asset Service: %s", ServiceURLsConfig.AssetService)
|
||
log.Printf(" User Service: %s", ServiceURLsConfig.UserService)
|
||
log.Printf(" Task Service: %s", ServiceURLsConfig.TaskService)
|
||
}
|