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
+16.9k Golang : Read integer from file into array
+17k Golang : Fix cannot convert buffer (type *bytes.Buffer) to type string error
+19.7k Golang : Archive directory with tar and gzip
+11.9k Golang : Convert(cast) bigint to string
+7.7k Golang : Mapping Iban to Dunging alphabets
+12.4k Elastic Search : Return all records (higher than default 10)
+36.3k Golang : How to split or chunking a file to smaller pieces?
+13.4k Golang : Increment string example
+36.6k Golang : Validate IP address
+9.5k Golang : Changing a RGBA image number of channels with OpenCV
+16.3k Golang : How to extract links from web page ?
+9.4k Facebook : Getting the friends list with PHP return JSON format