package config import ( "fmt" "os" "gopkg.in/yaml.v3" ) // LogConfig holds logging configuration values. type LogConfig struct { Level string `yaml:"level"` // debug, info, warn, error (default: info) Encoding string `yaml:"encoding"` // json, console (default: json) OutputStdout *bool `yaml:"output_stdout"` // 输出到终端 (default: true) FilePath string `yaml:"file_path"` // log file path (for rotation) MaxSize int `yaml:"max_size"` // MB per file (default: 100) MaxBackups int `yaml:"max_backups"` // retained files (default: 5) MaxAge int `yaml:"max_age"` // days to retain (default: 30) Compress bool `yaml:"compress"` // gzip old files (default: true) GormLevel string `yaml:"gorm_level"` // GORM SQL log level (default: warn) } // Config holds all application configuration values. type Config struct { ServerPort string `yaml:"server_port"` SlurmAPIURL string `yaml:"slurm_api_url"` SlurmUserName string `yaml:"slurm_user_name"` SlurmJWTKeyPath string `yaml:"slurm_jwt_key_path"` MySQLDSN string `yaml:"mysql_dsn"` Log LogConfig `yaml:"log"` } // Load reads a YAML configuration file and returns a parsed Config. // If path is empty, it defaults to "./config.yaml". func Load(path string) (*Config, error) { if path == "" { path = "./config.yaml" } data, err := os.ReadFile(path) if err != nil { return nil, fmt.Errorf("read config file %s: %w", path, err) } var cfg Config if err := yaml.Unmarshal(data, &cfg); err != nil { return nil, fmt.Errorf("parse config file %s: %w", path, err) } return &cfg, nil }