content-type
This commit is contained in:
parent
863d64b53a
commit
6770bae66a
|
|
@ -21,17 +21,99 @@ func contentType2Ext(contentType string) string {
|
||||||
|
|
||||||
func ext2ContentType(ext string) string {
|
func ext2ContentType(ext string) string {
|
||||||
ext = strings.ToLower(ext)
|
ext = strings.ToLower(ext)
|
||||||
if ext == "jpg" || ext == "jpeg" {
|
switch ext {
|
||||||
|
// 图片格式
|
||||||
|
case "jpg", "jpeg":
|
||||||
return "image/jpeg"
|
return "image/jpeg"
|
||||||
} else if ext == "png" {
|
case "png":
|
||||||
return "image/png"
|
return "image/png"
|
||||||
} else if ext == "mp3" {
|
case "gif":
|
||||||
|
return "image/gif"
|
||||||
|
case "webp":
|
||||||
|
return "image/webp"
|
||||||
|
case "bmp":
|
||||||
|
return "image/bmp"
|
||||||
|
case "svg", "svgz":
|
||||||
|
return "image/svg+xml"
|
||||||
|
case "ico":
|
||||||
|
return "image/x-icon"
|
||||||
|
case "tiff", "tif":
|
||||||
|
return "image/tiff"
|
||||||
|
case "avif":
|
||||||
|
return "image/avif"
|
||||||
|
case "apng":
|
||||||
|
return "image/apng"
|
||||||
|
// 音频格式
|
||||||
|
case "mp3":
|
||||||
return "audio/mpeg"
|
return "audio/mpeg"
|
||||||
} else if ext == "mp4" {
|
case "wav":
|
||||||
|
return "audio/wav"
|
||||||
|
case "ogg":
|
||||||
|
return "audio/ogg"
|
||||||
|
case "flac":
|
||||||
|
return "audio/flac"
|
||||||
|
case "aac":
|
||||||
|
return "audio/aac"
|
||||||
|
case "m4a":
|
||||||
|
return "audio/mp4"
|
||||||
|
// 视频格式
|
||||||
|
case "mp4":
|
||||||
return "video/mp4"
|
return "video/mp4"
|
||||||
}
|
case "avi":
|
||||||
|
return "video/x-msvideo"
|
||||||
|
case "mov", "qt":
|
||||||
|
return "video/quicktime"
|
||||||
|
case "webm":
|
||||||
|
return "video/webm"
|
||||||
|
case "flv":
|
||||||
|
return "video/x-flv"
|
||||||
|
case "mkv":
|
||||||
|
return "video/x-matroska"
|
||||||
|
case "wmv":
|
||||||
|
return "video/x-ms-wmv"
|
||||||
|
case "m3u8":
|
||||||
|
return "application/vnd.apple.mpegurl"
|
||||||
|
case "ts":
|
||||||
|
return "video/mp2t"
|
||||||
|
// 文档格式
|
||||||
|
case "pdf":
|
||||||
|
return "application/pdf"
|
||||||
|
case "doc":
|
||||||
|
return "application/msword"
|
||||||
|
case "docx":
|
||||||
|
return "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
||||||
|
case "xls":
|
||||||
|
return "application/vnd.ms-excel"
|
||||||
|
case "xlsx":
|
||||||
|
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
||||||
|
case "ppt":
|
||||||
|
return "application/vnd.ms-powerpoint"
|
||||||
|
case "pptx":
|
||||||
|
return "application/vnd.openxmlformats-officedocument.presentationml.presentation"
|
||||||
|
case "txt":
|
||||||
|
return "text/plain"
|
||||||
|
case "html", "htm":
|
||||||
|
return "text/html"
|
||||||
|
case "css":
|
||||||
|
return "text/css"
|
||||||
|
case "js":
|
||||||
|
return "application/javascript"
|
||||||
|
case "json":
|
||||||
|
return "application/json"
|
||||||
|
case "xml":
|
||||||
|
return "application/xml"
|
||||||
|
case "zip":
|
||||||
|
return "application/zip"
|
||||||
|
case "rar":
|
||||||
|
return "application/x-rar-compressed"
|
||||||
|
case "7z":
|
||||||
|
return "application/x-7z-compressed"
|
||||||
|
case "gz":
|
||||||
|
return "application/gzip"
|
||||||
|
default:
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func Download(url, path string) error {
|
func Download(url, path string) error {
|
||||||
f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue