升级FileType枚举类型定义

This commit is contained in:
白茶清欢 2024-11-25 16:18:53 +08:00
parent 42ae8fe5eb
commit 2d10d261da
4 changed files with 27 additions and 3 deletions

View File

@ -154,7 +154,7 @@ func (f *file) ReadAnyFileContent(filePath string, receiver any) error {
parseFunc func(filePath string, receiver any) error
)
fileExt := strings.TrimLeft(strings.ToLower(path.Ext(filePath)), ".")
fileExt := consts.FileType(strings.TrimLeft(strings.ToLower(path.Ext(filePath)), "."))
switch fileExt {
case consts.FileTypeJson:
parseFunc = f.ReadJSONContent
@ -167,7 +167,7 @@ func (f *file) ReadAnyFileContent(filePath string, receiver any) error {
case consts.FileTypeXml:
parseFunc = f.ReadXmlContent
default:
return errors.New(fileExt + " 暂不支持当前格式的文件解析")
return errors.New(fileExt.String() + " 暂不支持当前格式的文件解析")
}
return parseFunc(filePath, receiver)
}

22
file_test.go Normal file
View File

@ -0,0 +1,22 @@
// Package serialize ...
//
// Description : serialize ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2024-11-15 15:36
package serialize
import (
"fmt"
"testing"
)
func Test_file_ReadDirFileList(t *testing.T) {
f := &file{}
fileList, err := f.ReadDirFileList("/Users/zhangdeman/project/go-project/wrapper", true, true)
if nil != err {
panic(err.Error())
}
fmt.Println(JSON.MarshalForString(fileList))
}

2
go.mod
View File

@ -11,7 +11,7 @@ require (
gopkg.in/yaml.v3 v3.0.1
)
require git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241104082108-0f97a870bbc3
require git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241125081557-cacc6b3cafc6
require (
github.com/sbabiv/xml2map v1.2.1

2
go.sum
View File

@ -1,5 +1,7 @@
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241104082108-0f97a870bbc3 h1:BiAlBJ+DuRs/xD7nDQD2JT8Oc+V+0Uwt36qZwdXGvzI=
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241104082108-0f97a870bbc3/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241125081557-cacc6b3cafc6 h1:f24T6CtVn8bF84fbXpWTzS47otE+U2IdBj3cZero+OQ=
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241125081557-cacc6b3cafc6/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
git.zhangdeman.cn/zhangdeman/util v0.0.0-20240618042405-6ee2c904644e h1:Q973S6CcWr1ICZhFI1STFOJ+KUImCl2BaIXm6YppBqI=
git.zhangdeman.cn/zhangdeman/util v0.0.0-20240618042405-6ee2c904644e/go.mod h1:VpPjBlwz8U+OxZuxzHQBv1aEEZ3pStH6bZvT21ADEbI=
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=