-
Notifications
You must be signed in to change notification settings - Fork 4
/
filetype.go
108 lines (96 loc) · 1.81 KB
/
filetype.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package wfs
import (
"path/filepath"
"strings"
)
var types map[string]string
func init() {
types = map[string]string{
"docx": "document",
"doc": "document",
"odt": "document",
"xls": "document",
"xlsx": "document",
"ods": "document",
"pdf": "document",
"djvu": "document",
"djv": "document",
"pptx": "document",
"ppt": "document",
"html": "code",
"htm": "code",
"js": "code",
"ts": "code",
"mjs": "code",
"json": "code",
"css": "code",
"scss": "code",
"sass": "code",
"less": "code",
"php": "code",
"phtml": "code",
"php3": "code",
"php4": "code",
"php5": "code",
"php7": "code",
"php-s": "code",
"pht": "code",
"phar": "code",
"sh": "code",
"coffee": "code",
"txt": "code",
"md": "code",
"go": "code",
"yml": "code",
"yaml": "code",
"xml": "code",
"sql": "code",
"sqlite3": "code",
"sqlite": "code",
"db": "code",
"py": "code",
"pyc": "code",
"pyd": "code",
"pyo": "code",
"pyw": "code",
"pyz": "code",
"ini": "code",
"conf": "code",
"mpg": "video",
"mp4": "video",
"avi": "video",
"mkv": "video",
"ogv": "video",
"png": "image",
"jpg": "image",
"jpeg": "image",
"webp": "image",
"gif": "image",
"tiff": "image",
"tif": "image",
"svg": "image",
"mp3": "audio",
"ogg": "audio",
"flac": "audio",
"wav": "audio",
"zip": "archive",
"rar": "archive",
"7z": "archive",
"tar": "archive",
"gz": "archive",
}
}
func GetType(name string, isFolder bool) string {
if isFolder {
return "folder"
}
ext := filepath.Ext(name)
if ext == "" {
return "file"
}
ftype, ok := types[strings.ToLower(ext[1:])]
if !ok {
return "file"
}
return ftype
}