更新枚举类型定义

This commit is contained in:
2024-11-25 16:15:57 +08:00
parent f919222003
commit cacc6b3caf
5 changed files with 174 additions and 66 deletions

View File

@ -7,13 +7,41 @@
// Date : 2023-08-11 10:59
package consts
type FileType string
func (ft FileType) String() string {
return string(ft)
}
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 {
return true
}
}
return false
}
const (
FileTypeJson = "json" // json格式文件
FileTypeIni = "ini" // ini格式文件
FileTypeYml = "yml" // yml 格式文件
FileTypeYaml = "yaml" // yaml格式文件
FileTypeToml = "toml" // toml格式文件
FileTypeXml = "xml" // xml格式文件
FileTypeTxt = "txt" // txt格式文件
FileTypeUnknown = "unknown" // 未知格式
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" // 未知格式
)