修复相关BUG + 增加单元测试, 覆盖率100%
This commit is contained in:
61
file_type.go
61
file_type.go
@ -9,26 +9,17 @@ package consts
|
||||
|
||||
type FileType string
|
||||
|
||||
func (ft *FileType) String() string {
|
||||
return string(*ft)
|
||||
func (ft FileType) String() string {
|
||||
return string(ft)
|
||||
}
|
||||
|
||||
func (ft *FileType) MarshalJSON() ([]byte, error) {
|
||||
return []byte(ft.String()), nil
|
||||
func (ft FileType) MarshalJSON() ([]byte, error) {
|
||||
return []byte(`"` + ft.String() + `"`), nil
|
||||
}
|
||||
|
||||
func (ft *FileType) IsValid() bool {
|
||||
supportFileTypeList := []FileType{
|
||||
FileTypeJson,
|
||||
FileTypeIni,
|
||||
FileTypeYml,
|
||||
FileTypeYaml,
|
||||
FileTypeToml,
|
||||
FileTypeXml,
|
||||
FileTypeTxt,
|
||||
}
|
||||
for _, fileType := range supportFileTypeList {
|
||||
if fileType == *ft {
|
||||
func (ft FileType) IsValid() bool {
|
||||
for _, fileType := range SupportFileTypeList {
|
||||
if fileType.Value == ft || fileType.Value.String() == ft.String() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -45,3 +36,41 @@ const (
|
||||
FileTypeTxt FileType = "txt" // txt格式文件
|
||||
FileTypeUnknown FileType = "unknown" // 未知格式
|
||||
)
|
||||
|
||||
type FileTypeDesc struct {
|
||||
Value FileType
|
||||
Desc string
|
||||
}
|
||||
|
||||
var (
|
||||
SupportFileTypeList = []FileTypeDesc{
|
||||
{
|
||||
Value: FileTypeJson,
|
||||
Desc: "json格式文件",
|
||||
},
|
||||
{
|
||||
Value: FileTypeIni,
|
||||
Desc: "init格式文件",
|
||||
},
|
||||
{
|
||||
Value: FileTypeYml,
|
||||
Desc: "yml格式文件",
|
||||
},
|
||||
{
|
||||
Value: FileTypeYaml,
|
||||
Desc: "yaml格式文件",
|
||||
},
|
||||
{
|
||||
Value: FileTypeToml,
|
||||
Desc: "toml格式文件",
|
||||
},
|
||||
{
|
||||
Value: FileTypeTxt,
|
||||
Desc: "txt格式文件",
|
||||
},
|
||||
{
|
||||
Value: FileTypeXml,
|
||||
Desc: "xml格式文件",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
Reference in New Issue
Block a user