Add WorkDirBase config field for auto-generated job working directories. Pattern: {base}/{app_name}/{timestamp}_{random}/
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)
Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
53 lines
1.7 KiB
Go
53 lines
1.7 KiB
Go
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"`
|
|
WorkDirBase string `yaml:"work_dir_base"` // base directory for job work dirs
|
|
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
|
|
}
|