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
+17.9k Golang : Login and logout a user after password verification and redirect example
+25.5k Golang : Generate MD5 checksum of a file
+12.3k Golang : How to check if a string starts or ends with certain characters or words?
+11.5k Golang : Change date format to yyyy-mm-dd
+9.7k PHP : Get coordinates latitude/longitude from string
+19.2k Golang : Check whether a network interface is up on your machine
+4.8k Facebook : How to place save to Facebook button on your website
+17.1k Golang : XML to JSON example
+7.8k Golang : Scan files for certain pattern and rename part of the files
+11.1k Golang : Simple image viewer with Go-GTK
+15.2k Golang : Accurate and reliable decimal calculations