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
+20.6k Nginx + FastCGI + Go Setup.
+5.3k Javascript : Shuffle or randomize array example
+8.8k Golang : Random integer with rand.Seed() within a given range
+7.9k Golang : Get today's weekday name and calculate target day distance example
+13.5k Facebook PHP getUser() returns 0
+7.5k Golang : Rot13 and Rot5 algorithms example
+10.1k Golang : Edge detection with Sobel method
+10.3k Golang : Convert file unix timestamp to UTC time example
+17.5k Golang : Clone with pointer and modify value
+13.4k Golang : Increment string example
+7.9k Golang : Gomobile init produce "iphoneos" cannot be located error
+5.2k Golang : Calculate half life decay example