fix: 配置文件目录不存在时创建
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@@ -181,7 +182,7 @@ func ConvertConfigToMap(configType, content string) (map[string]any, error) {
|
||||
|
||||
var configMap map[string]interface{}
|
||||
var err error
|
||||
if configType == "txt" {
|
||||
if configType == "" || configType == "txt" {
|
||||
configMap = map[string]interface{}{
|
||||
"txt": content,
|
||||
}
|
||||
@@ -221,5 +222,9 @@ func ConvertConfigToFile(configType, filePath string, data any) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(filepath.Dir(filePath), 0750); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(filePath, dataByte, 0644)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user