consts/file_type.go

48 lines
1.1 KiB
Go
Raw Normal View History

2023-08-11 11:03:00 +08:00
// Package consts ...
//
// Description : consts ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2023-08-11 10:59
package consts
2024-11-25 16:15:57 +08:00
type FileType string
2025-01-22 15:55:39 +08:00
func (ft *FileType) String() string {
return string(*ft)
2024-11-25 16:15:57 +08:00
}
2025-01-22 15:55:39 +08:00
func (ft *FileType) MarshalJSON() ([]byte, error) {
2024-11-25 16:15:57 +08:00
return []byte(ft.String()), nil
}
2025-01-22 15:55:39 +08:00
func (ft *FileType) IsValid() bool {
2024-11-25 16:15:57 +08:00
supportFileTypeList := []FileType{
FileTypeJson,
FileTypeIni,
FileTypeYml,
FileTypeYaml,
FileTypeToml,
FileTypeXml,
FileTypeTxt,
}
for _, fileType := range supportFileTypeList {
2025-01-22 15:55:39 +08:00
if fileType == *ft {
2024-11-25 16:15:57 +08:00
return true
}
}
return false
}
2023-08-11 11:03:00 +08:00
const (
2024-11-25 16:15:57 +08:00
FileTypeJson FileType = "json" // json格式文件
FileTypeIni FileType = "ini" // ini格式文件
FileTypeYml FileType = "yml" // yml 格式文件
FileTypeYaml FileType = "yaml" // yaml格式文件
FileTypeToml FileType = "toml" // toml格式文件
FileTypeXml FileType = "xml" // xml格式文件
FileTypeTxt FileType = "txt" // txt格式文件
FileTypeUnknown FileType = "unknown" // 未知格式
2023-08-11 11:03:00 +08:00
)