40760aa884
- server:Go 网关(WS 流式识别中继/计费配额/微信登录支付 mock/反馈/埋点),gummy provider 已真实联调 - desktop:Tauri 2(全局快捷键 push-to-talk/浮层/托盘/设置/登录购买/反馈/首启引导) - android:Compose 主 App + IME(键盘内录音直传) - ios:App + 键盘扩展(1A spike 实证键盘内不可录音,走 deep link 听写) - design/design-pipeline:设计系统 + token 导出 iOS/Android 主题 - doc:前后端设计文档(HTML);web:官网宣传页;todo:任务看板 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
85 lines
2.2 KiB
Go
85 lines
2.2 KiB
Go
// Package config 环境变量配置(密钥经部署注入,本地开发用 .env.local / docker compose)。
|
|
package config
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
)
|
|
|
|
type Config struct {
|
|
Addr string // HTTP 监听地址
|
|
PostgresDSN string
|
|
RedisAddr string
|
|
RedisDB int
|
|
|
|
JWTSecret string
|
|
JWTTTLHours int
|
|
|
|
// 微信开放平台 / 商户号(申请中可留空,相关模块降级为 mock)
|
|
WechatWebAppID string
|
|
WechatWebSecret string
|
|
WechatMobileAppID string
|
|
WechatMobileSecret string
|
|
WxPayMchID string
|
|
WxPayCertSerial string
|
|
WxPayPrivateKeyPEM string
|
|
WxPayAPIv3Key string
|
|
WxPayNotifyURL string
|
|
|
|
// ASR
|
|
ASRProvider string // gummy | mock
|
|
DashScopeAPIKey string
|
|
|
|
// OSS(反馈图片)
|
|
OSSEndpoint string
|
|
OSSBucket string
|
|
OSSKeyID string
|
|
OSSKeySecret string
|
|
}
|
|
|
|
func Load() Config {
|
|
return Config{
|
|
Addr: getenv("ADDR", ":8080"),
|
|
PostgresDSN: getenv("POSTGRES_DSN", "host=localhost user=dudu password=dudu dbname=dudu port=5432 sslmode=disable TimeZone=Asia/Shanghai"),
|
|
RedisAddr: getenv("REDIS_ADDR", "localhost:6379"),
|
|
RedisDB: getint("REDIS_DB", 0),
|
|
|
|
JWTSecret: getenv("JWT_SECRET", "dev-secret-change-me"),
|
|
JWTTTLHours: getint("JWT_TTL_HOURS", 24*7),
|
|
|
|
WechatWebAppID: os.Getenv("WECHAT_WEB_APPID"),
|
|
WechatWebSecret: os.Getenv("WECHAT_WEB_SECRET"),
|
|
WechatMobileAppID: os.Getenv("WECHAT_MOBILE_APPID"),
|
|
WechatMobileSecret: os.Getenv("WECHAT_MOBILE_SECRET"),
|
|
WxPayMchID: os.Getenv("WXPAY_MCHID"),
|
|
WxPayCertSerial: os.Getenv("WXPAY_CERT_SERIAL"),
|
|
WxPayPrivateKeyPEM: os.Getenv("WXPAY_PRIVATE_KEY_PEM"),
|
|
WxPayAPIv3Key: os.Getenv("WXPAY_APIV3_KEY"),
|
|
WxPayNotifyURL: os.Getenv("WXPAY_NOTIFY_URL"),
|
|
|
|
ASRProvider: getenv("ASR_PROVIDER", "mock"),
|
|
DashScopeAPIKey: os.Getenv("DASHSCOPE_API_KEY"),
|
|
|
|
OSSEndpoint: os.Getenv("OSS_ENDPOINT"),
|
|
OSSBucket: os.Getenv("OSS_BUCKET"),
|
|
OSSKeyID: os.Getenv("OSS_KEY_ID"),
|
|
OSSKeySecret: os.Getenv("OSS_KEY_SECRET"),
|
|
}
|
|
}
|
|
|
|
func getenv(k, def string) string {
|
|
if v := os.Getenv(k); v != "" {
|
|
return v
|
|
}
|
|
return def
|
|
}
|
|
|
|
func getint(k string, def int) int {
|
|
if v := os.Getenv(k); v != "" {
|
|
if n, err := strconv.Atoi(v); err == nil {
|
|
return n
|
|
}
|
|
}
|
|
return def
|
|
}
|