统一单入口 Go 工程与前端依赖目录,增加后台供应商配置、候选审核、计划预算、成交冲正、持仓复盘和站内通知。接入策略版本、Python 回测、可配置 A 股公开行情及 zap 文件轮转日志,补充迁移、契约与验证。
This commit is contained in:
@@ -4,6 +4,7 @@ package config
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"git.sundynix.cn/Blizzard/Veyra/internal/logging"
|
||||
"net"
|
||||
"net/url"
|
||||
"os"
|
||||
@@ -12,9 +13,12 @@ import (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
PythonExecutable string
|
||||
Logging logging.Options
|
||||
Environment, HTTPAddr string
|
||||
PGHost, PGPort, PGDatabase, PGUser, PGPassword, PGSSLMode, PGAdminDatabase string
|
||||
RedisAddr, RedisUsername, RedisPassword string
|
||||
SecretEncryptionKey string
|
||||
RedisDB int
|
||||
}
|
||||
|
||||
@@ -57,6 +61,18 @@ func LoadEnvFile(path string) error {
|
||||
|
||||
func Load() (Config, error) {
|
||||
c := Config{Environment: env("APP_ENV", "local"), HTTPAddr: env("HTTP_ADDR", "127.0.0.1:8080"), PGHost: env("PGHOST", "192.168.100.127"), PGPort: env("PGPORT", "5432"), PGDatabase: env("PGDATABASE", "veyra"), PGUser: os.Getenv("PGUSER"), PGPassword: os.Getenv("PGPASSWORD"), PGSSLMode: env("PGSSLMODE", "disable"), PGAdminDatabase: env("PGADMIN_DATABASE", "postgres"), RedisAddr: env("REDIS_ADDR", "192.168.100.127:6379"), RedisUsername: os.Getenv("REDIS_USERNAME"), RedisPassword: os.Getenv("REDIS_PASSWORD")}
|
||||
c.PythonExecutable = env("PYTHON_EXECUTABLE", "python3")
|
||||
c.Logging = logging.Options{Directory: env("LOG_DIR", "logs"), Level: env("LOG_LEVEL", "info"), MaxSizeMB: 50, MaxBackups: 10, MaxAgeDays: 14}
|
||||
for key, dest := range map[string]*int{"LOG_MAX_SIZE_MB": &c.Logging.MaxSizeMB, "LOG_MAX_BACKUPS": &c.Logging.MaxBackups, "LOG_MAX_AGE_DAYS": &c.Logging.MaxAgeDays} {
|
||||
if value := os.Getenv(key); value != "" {
|
||||
n, err := strconv.Atoi(value)
|
||||
if err != nil || n < 1 {
|
||||
return Config{}, fmt.Errorf("%s must be a positive integer", key)
|
||||
}
|
||||
*dest = n
|
||||
}
|
||||
}
|
||||
c.SecretEncryptionKey = os.Getenv("SECRET_ENCRYPTION_KEY")
|
||||
var err error
|
||||
c.RedisDB, err = strconv.Atoi(env("REDIS_DB", "0"))
|
||||
if err != nil || c.RedisDB < 0 {
|
||||
@@ -82,7 +98,7 @@ func Load() (Config, error) {
|
||||
|
||||
func (c Config) ValidateDatabase() error {
|
||||
if c.PGUser == "" {
|
||||
return fmt.Errorf("PGUSER is required; configure the local .env file")
|
||||
return fmt.Errorf("PGUSER is required; configure the local configs/.env file")
|
||||
}
|
||||
if c.PGHost == "" || c.PGDatabase == "" || c.PGAdminDatabase == "" {
|
||||
return fmt.Errorf("database host and names are required")
|
||||
|
||||
Reference in New Issue
Block a user