Golang mime.TypeByExtension() function example
package mime
Golang mime.TypeByExtension() function usage example
package main
import (
"fmt"
"mime"
"os"
"path/filepath"
)
func main() {
if len(os.Args) != 2 {
fmt.Printf("Usage : %s filename \n", os.Args[0])
os.Exit(1)
}
// get file extension
ext := filepath.Ext(os.Args[1])
mType := mime.TypeByExtension(ext)
fmt.Println("Media type : ", mType)
}
References :
https://www.socketloop.com/tutorials/golang-find-files-by-extension
Advertisement
Something interesting
Tutorials
+5.4k Javascript : How to loop over and parse JSON data?
+19.9k Golang : Count JSON objects and convert to slice/array
+11.5k Use systeminfo to find out installed Windows Hotfix(s) or updates
+18.7k Golang : Implement getters and setters
+24.5k Golang : Time slice or date sort and reverse sort example
+10.9k Golang : Removes punctuation or defined delimiter from the user's input
+26.9k Golang : Force your program to run with root permissions
+17.5k Golang : Find smallest number in array
+21.6k Golang : GORM create record or insert new record into database example
+5.6k Fix fatal error: evacuation not done in time problem
+16.6k Golang : Generate QR codes for Google Authenticator App and fix "Cannot interpret QR code" error
+8.3k Golang : Oanda bot with Telegram and RSI example