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
+13.2k Golang : Convert(cast) int to int64
+7.3k Golang : Calculate how many weeks left to go in a given year
+18.7k Unmarshal/Load CSV record into struct in Go
+25.3k Golang : Convert uint value to string type
+18.1k Golang : Check if a directory exist or not
+5.5k Golang : Stop goroutine without channel
+14.9k Golang : Basic authentication with .htpasswd file
+12.7k Golang : Remove or trim extra comma from CSV
+6.9k Golang : How to solve "too many .rsrc sections" error?
+25.3k Golang : Get current file path of a file or executable
+4.7k Golang : How to pass data between controllers with JSON Web Token
+6.9k Mac/Linux/Windows : Get CPU information from command line