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
+11.2k Google Maps URL parameters configuration
+10.1k Golang : Identifying Golang HTTP client request
+18.2k Golang : Get command line arguments
+11k Golang : Replace a parameter's value inside a configuration file example
+9.5k Mac OSX : Get a process/daemon status information
+13.2k CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message
+8.2k Golang : Add build version and other information in executables
+13.2k Golang : Skip blank/empty lines in CSV file and trim whitespaces example
+6.3k Golang : Extract sub-strings
+19.7k Golang : Archive directory with tar and gzip
+8.2k Golang : Find relative luminance or color brightness