- 新增许愿树页面(Canvas绘制、许愿条展示) - 新增许愿详情页面 - 新增许愿创建弹窗(免费/付费两种模式) - 新增网络请求封装 utils/request.js - 新增Go后端项目结构(Gin + Inertia.js) - 新增用户、订单、许愿数据模型 - 新增数据库迁移脚本 - 更新.gitignore补全忽略规则 - 更新.env.local配置(robot=2, 版本1.0.1) - 添加secrets目录说明文档
83 lines
1.5 KiB
Go
83 lines
1.5 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
)
|
|
|
|
type Config struct {
|
|
Server ServerConfig
|
|
Database DatabaseConfig
|
|
Redis RedisConfig
|
|
JWT JWTConfig
|
|
Wechat WechatConfig
|
|
}
|
|
|
|
type ServerConfig struct {
|
|
Port string
|
|
Env string
|
|
}
|
|
|
|
type DatabaseConfig struct {
|
|
Host string
|
|
Port string
|
|
User string
|
|
Password string
|
|
Name string
|
|
}
|
|
|
|
type RedisConfig struct {
|
|
Host string
|
|
Port string
|
|
Password string
|
|
DB int
|
|
}
|
|
|
|
type JWTConfig struct {
|
|
Secret string
|
|
}
|
|
|
|
type WechatConfig struct {
|
|
AppID string
|
|
AppSecret string
|
|
PayKey string
|
|
MchID string
|
|
}
|
|
|
|
func Load() *Config {
|
|
return &Config{
|
|
Server: ServerConfig{
|
|
Port: getEnv("SERVER_PORT", "8080"),
|
|
Env: getEnv("SERVER_ENV", "development"),
|
|
},
|
|
Database: DatabaseConfig{
|
|
Host: getEnv("DB_HOST", "localhost"),
|
|
Port: getEnv("DB_PORT", "3306"),
|
|
User: getEnv("DB_USER", "root"),
|
|
Password: getEnv("DB_PASSWORD", ""),
|
|
Name: getEnv("DB_NAME", "lunar"),
|
|
},
|
|
Redis: RedisConfig{
|
|
Host: getEnv("REDIS_HOST", "localhost"),
|
|
Port: getEnv("REDIS_PORT", "6379"),
|
|
Password: getEnv("REDIS_PASSWORD", ""),
|
|
DB: 0,
|
|
},
|
|
JWT: JWTConfig{
|
|
Secret: getEnv("JWT_SECRET", "your-secret-key"),
|
|
},
|
|
Wechat: WechatConfig{
|
|
AppID: getEnv("MINI_APP_ID", ""),
|
|
AppSecret: getEnv("MINI_APP_SECRET", ""),
|
|
PayKey: getEnv("WECHAT_PAY_APIKEY", ""),
|
|
MchID: getEnv("WECHAT_PAY_MCHID", ""),
|
|
},
|
|
}
|
|
}
|
|
|
|
func getEnv(key, defaultValue string) string {
|
|
if value := os.Getenv(key); value != "" {
|
|
return value
|
|
}
|
|
return defaultValue
|
|
}
|