go get github.com/vimeo/go-magic/magic
libmagic
URL: http://www.darwinsys.com/file/
Ubuntu: apt-get install libmagic-dev
CentOS: yum install file-devel
- Create some custom magic files (e.g. ~/magicfiles)
- Add the default system magic file dir
- magic.AddMagicDir(magic.GetDefaultDir())
- Add the custom magic file dir
- magic.AddMagicDir("~/magicfiles")
- Get MIME type with either one of:
- magic.MimeFromFile(filename)
- magic.MimeFromBytes(data)