main pico / pkg / shared / mime / mime.go
Eric Bower  ·  2026-07-16
  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", ".html":
 22		return "text/html"
 23	case ".jpeg", ".jpg":
 24		return "image/jpeg"
 25	case ".png":
 26		return "image/png"
 27	case ".gif":
 28		return "image/gif"
 29	case ".webp":
 30		return "image/webp"
 31	case ".otf":
 32		return "font/otf"
 33	case ".woff":
 34		return "font/woff"
 35	case ".woff2":
 36		return "font/woff2"
 37	case ".ttf":
 38		return "font/ttf"
 39	case ".md":
 40		return "text/markdown; charset=UTF-8"
 41	case ".map", ".json":
 42		return "application/json"
 43	case ".rss":
 44		return "application/rss+xml"
 45	case ".atom":
 46		return "application/atom+xml"
 47	case ".webmanifest":
 48		return "application/manifest+json"
 49	case ".xml":
 50		return "application/xml"
 51	case ".xsl":
 52		return "application/xml"
 53	case ".avif":
 54		return "image/avif"
 55	case ".heif":
 56		return "image/heif"
 57	case ".heic":
 58		return "image/heif"
 59	case ".opus":
 60		return "audio/opus"
 61	case ".wav":
 62		return "audio/wav"
 63	case ".mp3":
 64		return "audio/mpeg"
 65	case ".mp4":
 66		return "video/mp4"
 67	case ".mpeg":
 68		return "video/mpeg"
 69	case ".wasm":
 70		return "application/wasm"
 71	case ".opml":
 72		return "text/x-opml"
 73	case ".eot":
 74		return "application/vnd.ms-fontobject"
 75	case ".yaml", ".yml":
 76		return "text/x-yaml"
 77	case ".zip":
 78		return "application/zip"
 79	case ".rar":
 80		return "application/vnd.rar"
 81	case ".gz":
 82		return "application/gzip"
 83	case ".bz":
 84		return "application/x-bzip"
 85	case ".bz2":
 86		return "application/x-bzip2"
 87	case ".xz":
 88		return "application/x-xz"
 89	case ".7z":
 90		return "application/x-7z-compressed"
 91	case ".tar":
 92		return "application/x-tar"
 93	case ".arc":
 94		return "application/x-freearc"
 95	case ".txt":
 96		return "text/plain"
 97	}
 98
 99	return "text/plain"
100}