|
|
|
@@ -8,6 +8,7 @@
|
|
|
|
|
package serialize
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/xml"
|
|
|
|
|
"errors"
|
|
|
|
|
"git.zhangdeman.cn/zhangdeman/consts"
|
|
|
|
|
"io"
|
|
|
|
@@ -22,8 +23,6 @@ import (
|
|
|
|
|
"git.zhangdeman.cn/zhangdeman/util/define"
|
|
|
|
|
|
|
|
|
|
"github.com/go-ini/ini"
|
|
|
|
|
|
|
|
|
|
yml "gopkg.in/yaml.v3"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
@@ -78,7 +77,7 @@ func (f *file) ReadYmlContent(filePath string, result any) error {
|
|
|
|
|
if fileContent, err = f.ReadFileContent(filePath); nil != err {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return yml.Unmarshal(fileContent, result)
|
|
|
|
|
return Yml.UnmarshalWithNumber(fileContent, result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ReadJSONContent 读取JSON内容,并解析到指定的结构体中
|
|
|
|
@@ -127,6 +126,24 @@ func (f *file) ReadTomlContent(filePath string, result any) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ReadXmlContent ...
|
|
|
|
|
//
|
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
|
//
|
|
|
|
|
// Date : 18:39 2024/10/23
|
|
|
|
|
func (f *file) ReadXmlContent(filePath string, result any) error {
|
|
|
|
|
var (
|
|
|
|
|
fileContent []byte
|
|
|
|
|
err error
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if fileContent, err = f.ReadFileContent(filePath); nil != err {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return xml.Unmarshal(fileContent, result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ReadAnyFileContent 读取任意类型的文件并解析
|
|
|
|
|
//
|
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
@@ -153,6 +170,8 @@ func (f *file) ReadAnyFileContent(filePath string, receiver any) error {
|
|
|
|
|
parseFunc = f.ReadIniContent
|
|
|
|
|
case consts.FileTypeToml:
|
|
|
|
|
parseFunc = f.ReadTomlContent
|
|
|
|
|
case consts.FileTypeXml:
|
|
|
|
|
parseFunc = f.ReadXmlContent
|
|
|
|
|
default:
|
|
|
|
|
return errors.New(fileExt + " 暂不支持当前格式的文件解析")
|
|
|
|
|
}
|
|
|
|
|