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
+6.8k Swift : substringWithRange() function example
+4.7k Fix Google Analytics Redundant Hostnames problem
+5.2k Golang : Experimental Jawi programming language
+7.5k Golang : Dealing with struct's private part
+15.2k Golang : How to add color to string?
+14.8k Golang : Get URI segments by number and assign as variable example
+9.7k Golang : interface - when and where to use examples
+23.5k Golang : Check if element exist in map
+11.8k Golang : convert(cast) float to string
+14.9k Golang : Basic authentication with .htpasswd file
+13.1k Golang : Handle or parse date string with Z suffix(RFC3339) example
+6.9k Golang : Fibonacci number generator examples