Skip to content

Instantly share code, notes, and snippets.

@tomohiro
Last active August 29, 2015 14:06
Show Gist options
  • Save tomohiro/80ee263b44e32161a5d0 to your computer and use it in GitHub Desktop.
Save tomohiro/80ee263b44e32161a5d0 to your computer and use it in GitHub Desktop.
Check mimetype of images
// Usage:
// $ go run mime.go
// foo.png -> image/png
// bar.jpg -> image/jpeg
// baz.gif -> image/gif
// foo.bmp -> image/bmp
//
// Description:
// Check mimetype of images
//
package main
import (
"fmt"
"mime"
"path/filepath"
)
func main() {
images := []string{"foo.png", "bar.jpg", "baz.gif", "foo.bmp"}
for _, f := range images {
mt := mime.TypeByExtension(filepath.Ext(f))
fmt.Printf("%s -> %s\n", f, mt)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment