mirror of
https://github.com/safing/portbase
synced 2025-04-23 02:39:09 +00:00
Add MimeTypeByExtension
This commit is contained in:
parent
5150a030bf
commit
2c0a2b26fd
2 changed files with 78 additions and 2 deletions
78
utils/mimetypes.go
Normal file
78
utils/mimetypes.go
Normal file
|
@ -0,0 +1,78 @@
|
|||
package utils
|
||||
|
||||
import "strings"
|
||||
|
||||
// Do not depend on the OS for mimetypes.
|
||||
// A Windows update screwed us over here and broke all the automatic mime
|
||||
// typing via Go in April 2021.
|
||||
|
||||
// MimeTypeByExtension returns a mimetype for the given file name extension,
|
||||
// which must including the leading dot.
|
||||
// If the extension is not known, the call returns with ok=false and,
|
||||
// additionally, a default "application/octet-stream" mime type is returned.
|
||||
func MimeTypeByExtension(ext string) (mimeType string, ok bool) {
|
||||
mimeType, ok = mimeTypes[strings.ToLower(ext)]
|
||||
if ok {
|
||||
return
|
||||
}
|
||||
|
||||
return defaultMimeType, false
|
||||
}
|
||||
|
||||
var (
|
||||
defaultMimeType = "application/octet-stream"
|
||||
|
||||
mimeTypes = map[string]string{
|
||||
".7z": "application/x-7z-compressed",
|
||||
".atom": "application/atom+xml",
|
||||
".css": "text/css; charset=utf-8",
|
||||
".csv": "text/csv; charset=utf-8",
|
||||
".deb": "application/x-debian-package",
|
||||
".epub": "application/epub+zip",
|
||||
".es": "application/ecmascript",
|
||||
".flv": "video/x-flv",
|
||||
".gif": "image/gif",
|
||||
".gz": "application/gzip",
|
||||
".htm": "text/html; charset=utf-8",
|
||||
".html": "text/html; charset=utf-8",
|
||||
".jpeg": "image/jpeg",
|
||||
".jpg": "image/jpeg",
|
||||
".js": "text/javascript; charset=utf-8",
|
||||
".json": "application/json; charset=utf-8",
|
||||
".m3u": "audio/mpegurl",
|
||||
".m4a": "audio/mpeg",
|
||||
".md": "text/markdown; charset=utf-8",
|
||||
".mjs": "text/javascript; charset=utf-8",
|
||||
".mov": "video/quicktime",
|
||||
".mp3": "audio/mpeg",
|
||||
".mp4": "video/mp4",
|
||||
".mpeg": "video/mpeg",
|
||||
".mpg": "video/mpeg",
|
||||
".ogg": "audio/ogg",
|
||||
".ogv": "video/ogg",
|
||||
".otf": "font/otf",
|
||||
".pdf": "application/pdf",
|
||||
".png": "image/png",
|
||||
".qt": "video/quicktime",
|
||||
".rar": "application/rar",
|
||||
".rtf": "application/rtf",
|
||||
".svg": "image/svg+xml",
|
||||
".tar": "application/x-tar",
|
||||
".tiff": "image/tiff",
|
||||
".ts": "video/MP2T",
|
||||
".ttc": "font/collection",
|
||||
".ttf": "font/ttf",
|
||||
".txt": "text/plain; charset=utf-8",
|
||||
".wasm": "application/wasm",
|
||||
".wav": "audio/x-wav",
|
||||
".webm": "video/webm",
|
||||
".webp": "image/webp",
|
||||
".woff": "font/woff",
|
||||
".woff2": "font/woff2",
|
||||
".xml": "text/xml; charset=utf-8",
|
||||
".xz": "application/x-xz",
|
||||
".yaml": "application/yaml; charset=utf-8",
|
||||
".yml": "application/yaml; charset=utf-8",
|
||||
".zip": "application/zip",
|
||||
}
|
||||
)
|
|
@ -2,8 +2,6 @@ package utils
|
|||
|
||||
import "sync"
|
||||
|
||||
// This file is forked from https://github.com/golang/go/blob/bc593eac2dc63d979a575eccb16c7369a5ff81e0/src/sync/once.go.
|
||||
|
||||
// A StablePool is a drop-in replacement for sync.Pool that is slower, but
|
||||
// predictable.
|
||||
// A StablePool is a set of temporary objects that may be individually saved and
|
||||
|
|
Loading…
Add table
Reference in a new issue