Eric Bower
·
2026-04-20
mime.go
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 ".svg":
12 return "image/svg+xml"
13 case ".css":
14 return "text/css"
15 case ".js":
16 return "text/javascript"
17 case ".ico":
18 return "image/x-icon"
19 case ".pdf":
20 return "application/pdf"
21 case ".htm":
22 case ".html":
23 return "text/html"
24 case ".jpeg":
25 case ".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":
44 case ".json":
45 return "application/json"
46 case ".rss":
47 return "application/rss+xml"
48 case ".atom":
49 return "application/atom+xml"
50 case ".webmanifest":
51 return "application/manifest+json"
52 case ".xml":
53 return "application/xml"
54 case ".xsl":
55 return "application/xml"
56 case ".avif":
57 return "image/avif"
58 case ".heif":
59 return "image/heif"
60 case ".heic":
61 return "image/heif"
62 case ".opus":
63 return "audio/opus"
64 case ".wav":
65 return "audio/wav"
66 case ".mp3":
67 return "audio/mpeg"
68 case ".mp4":
69 return "video/mp4"
70 case ".mpeg":
71 return "video/mpeg"
72 case ".wasm":
73 return "application/wasm"
74 case ".opml":
75 return "text/x-opml"
76 case ".eot":
77 return "application/vnd.ms-fontobject"
78 case ".yaml":
79 case ".yml":
80 return "text/x-yaml"
81 case ".zip":
82 return "application/zip"
83 case ".rar":
84 return "application/vnd.rar"
85 case ".gz":
86 return "application/gzip"
87 case ".bz":
88 return "application/x-bzip"
89 case ".bz2":
90 return "application/x-bzip2"
91 case ".xz":
92 return "application/x-xz"
93 case ".7z":
94 return "application/x-7z-compressed"
95 case ".tar":
96 return "application/x-tar"
97 case ".arc":
98 return "application/x-freearc"
99 case ".txt":
100 return "text/plain"
101 }
102
103 return "text/plain"
104}