升级FileType枚举类型定义
This commit is contained in:
		
							
								
								
									
										4
									
								
								file.go
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								file.go
									
									
									
									
									
								
							@ -154,7 +154,7 @@ func (f *file) ReadAnyFileContent(filePath string, receiver any) error {
 | 
				
			|||||||
		parseFunc func(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 {
 | 
						switch fileExt {
 | 
				
			||||||
	case consts.FileTypeJson:
 | 
						case consts.FileTypeJson:
 | 
				
			||||||
		parseFunc = f.ReadJSONContent
 | 
							parseFunc = f.ReadJSONContent
 | 
				
			||||||
@ -167,7 +167,7 @@ func (f *file) ReadAnyFileContent(filePath string, receiver any) error {
 | 
				
			|||||||
	case consts.FileTypeXml:
 | 
						case consts.FileTypeXml:
 | 
				
			||||||
		parseFunc = f.ReadXmlContent
 | 
							parseFunc = f.ReadXmlContent
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		return errors.New(fileExt + " 暂不支持当前格式的文件解析")
 | 
							return errors.New(fileExt.String() + " 暂不支持当前格式的文件解析")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return parseFunc(filePath, receiver)
 | 
						return parseFunc(filePath, receiver)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										22
									
								
								file_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								file_test.go
									
									
									
									
									
										Normal 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
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.mod
									
									
									
									
									
								
							@ -11,7 +11,7 @@ require (
 | 
				
			|||||||
	gopkg.in/yaml.v3 v3.0.1
 | 
						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 (
 | 
					require (
 | 
				
			||||||
	github.com/sbabiv/xml2map v1.2.1
 | 
						github.com/sbabiv/xml2map v1.2.1
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										2
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								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 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-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 h1:Q973S6CcWr1ICZhFI1STFOJ+KUImCl2BaIXm6YppBqI=
 | 
				
			||||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20240618042405-6ee2c904644e/go.mod h1:VpPjBlwz8U+OxZuxzHQBv1aEEZ3pStH6bZvT21ADEbI=
 | 
					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=
 | 
					github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user