topfans/backend/services/galleryService/config/gallery_config.go
2026-04-07 22:29:48 +08:00

110 lines
3.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
}