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
+7.5k Golang : Get YouTube playlist
+11.7k Golang : Find age or leap age from date of birth example
+9k Golang : Inject/embed Javascript before sending out to browser example
+27.4k Golang : Convert CSV data to JSON format and save to file
+11.1k Golang : Roll the dice example
+10.5k Golang : Generate 403 Forbidden to protect a page or prevent indexing by search engine
+20.2k Golang : Convert seconds to human readable time format example
+8.2k How to show different content from website server when AdBlock is detected?
+7.4k Android Studio : How to detect camera, activate and capture example
+4.6k JavaScript : Rounding number to decimal formats to display currency
+5.6k PHP : Convert string to timestamp or datestamp before storing to database(MariaDB/MySQL)
+15.9k Golang : Read a file line by line