提供文件操作类utils内容

This commit is contained in:
2025-12-04 18:45:25 +08:00
parent 3707f519fe
commit d7ba7747ec
10 changed files with 669 additions and 16 deletions

View File

@@ -4,11 +4,8 @@
package config
import (
"fmt"
"os"
"git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
"gopkg.in/yaml.v2"
"git.huangwc.com/pig/pig-farm-controller/internal/infra/utils/file"
)
// Config 代表应用的完整配置结构
@@ -64,6 +61,7 @@ type AppConfig struct {
Name string `yaml:"name"`
Version string `yaml:"version"`
JWTSecret string `yaml:"jwt_secret"` // JWT 密钥
TempPath string `yaml:"temp_path"`
}
// ServerConfig 代表服务器配置
@@ -273,18 +271,7 @@ func NewConfig() *Config {
// Load 从指定路径加载配置文件
func (c *Config) Load(path string) error {
// 读取配置文件
data, err := os.ReadFile(path)
if err != nil {
return fmt.Errorf("配置文件读取失败: %v", err)
}
// 解析YAML配置
if err := yaml.Unmarshal(data, c); err != nil {
return fmt.Errorf("配置文件解析失败: %v", err)
}
return nil
return file.LoadYaml(path, c)
}
// GenerateAPIKey 用于补齐API Key作为请求头时缺失的部分