sean0407
·
2026-10-11
1package mime
2
3import (
4 "path/filepath"
5 "strings"
6)
7
8func GetMimeType(fpath string) string {
9 ext := strings.ToLower(filepath.Ext(fpath))
10 switch ext {
11 case ".bin":
12 return "application/octet-stream"
13 case ".svg":
14 return "image/svg+xml"
15 case ".css":
16 return "text/css"
17 case ".js":
18 return "text/javascript"
19 case ".ico":
20 return "image/x-icon"
21 case ".pdf":
22 return "application/pdf"
23 case ".htm", ".html":
24 return "text/html"
25 case ".jpeg", ".jpg":
26 return "image/jpeg"
27 case ".png":
28 return "image/png"
29 case ".gif":
30 return "image/gif"
31 case ".webp":
32 return "image/webp"
33 case ".otf":
34 return "font/otf"
35 case ".woff":
36 return "font/woff"
37 case ".woff2":
38 return "font/woff2"
39 case ".ttf":
40 return "font/ttf"
41 case ".md":
42 return "text/markdown; charset=UTF-8"
43 case ".map", ".json":
44 return "application/json"
45 case ".rss":
46 return "application/rss+xml"
47 case ".atom":
48 return "application/atom+xml"
49 case ".webmanifest":
50 return "application/manifest+json"
51 case ".xml":
52 return "application/xml"
53 case ".xsl":
54 return "application/xml"
55 case ".avif":
56 return "image/avif"
57 case ".heif":
58 return "image/heif"
59 case ".heic":
60 return "image/heif"
61 case ".opus":
62 return "audio/opus"
63 case ".wav":
64 return "audio/wav"
65 case ".mp3":
66 return "audio/mpeg"
67 case ".mp4":
68 return "video/mp4"
69 case ".mpeg":
70 return "video/mpeg"
71 case ".wasm":
72 return "application/wasm"
73 case ".opml":
74 return "text/x-opml"
75 case ".eot":
76 return "application/vnd.ms-fontobject"
77 case ".yaml", ".yml":
78 return "text/x-yaml"
79 case ".zip":
80 return "application/zip"
81 case ".rar":
82 return "application/vnd.rar"
83 case ".gz":
84 return "application/gzip"
85 case ".bz":
86 return "application/x-bzip"
87 case ".bz2":
88 return "application/x-bzip2"
89 case ".xz":
90 return "application/x-xz"
91 case ".7z":
92 return "application/x-7z-compressed"
93 case ".tar":
94 return "application/x-tar"
95 case ".arc":
96 return "application/x-freearc"
97 case ".txt":
98 return "text/plain"
99 }
100
101 return "text/plain"
102}