From 2d10d261da4c3fb5a5cb122824f4aa952724804b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Mon, 25 Nov 2024 16:18:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7FileType=E6=9E=9A=E4=B8=BE?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- file.go | 4 ++-- file_test.go | 22 ++++++++++++++++++++++ go.mod | 2 +- go.sum | 2 ++ 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 file_test.go diff --git a/file.go b/file.go index e59d62f..a238ced 100644 --- a/file.go +++ b/file.go @@ -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) } diff --git a/file_test.go b/file_test.go new file mode 100644 index 0000000..1f84bd3 --- /dev/null +++ b/file_test.go @@ -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)) +} diff --git a/go.mod b/go.mod index 5cb7ea3..2b6a88b 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index dfa6ff5..5cfad4b 100644 --- a/go.sum +++ b/go.sum @@ -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=