Files
hpc/internal/config/config.go
dailz 44895214d4 feat(config): add MinIO object storage configuration
Add MinioConfig struct with connection, bucket, chunk size, and session TTL settings.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-04-15 09:22:18 +08:00

80 lines
2.8 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)
}
// MinioConfig holds MinIO object storage configuration values.
type MinioConfig struct {
Endpoint string `yaml:"endpoint"` // MinIO server address
AccessKey string `yaml:"access_key"` // access key
SecretKey string `yaml:"secret_key"` // secret key
Bucket string `yaml:"bucket"` // bucket name
UseSSL bool `yaml:"use_ssl"` // use TLS connection
ChunkSize int64 `yaml:"chunk_size"` // upload chunk size in bytes (default: 16MB)
MaxFileSize int64 `yaml:"max_file_size"` // max file size in bytes (default: 50GB)
MinChunkSize int64 `yaml:"min_chunk_size"` // minimum chunk size in bytes (default: 5MB)
SessionTTL int `yaml:"session_ttl"` // session TTL in hours (default: 48)
}
// 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"`
Minio MinioConfig `yaml:"minio"`
}
// 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)
}
if cfg.Minio.ChunkSize == 0 {
cfg.Minio.ChunkSize = 16 << 20 // 16MB
}
if cfg.Minio.MaxFileSize == 0 {
cfg.Minio.MaxFileSize = 50 << 30 // 50GB
}
if cfg.Minio.MinChunkSize == 0 {
cfg.Minio.MinChunkSize = 5 << 20 // 5MB
}
if cfg.Minio.SessionTTL == 0 {
cfg.Minio.SessionTTL = 48
}
return &cfg, nil
}