Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to tell a file type (executable, text, etc.) in Go?

Tags:

go

It there a built-in way to get a file type in Go?

Is it sufficient to guess from the filename alone (in Windows) or is there a way to tell only basically if the file is, say, an executable file? I'd like to find a cross-platform method of doing this, and reading a filename and working from that may miss executable files that are renamed to *.jpg.

like image 740
Bart Silverstrim Avatar asked Feb 12 '14 19:02

Bart Silverstrim


1 Answers

You can either use MIME type guessing using mime.TypeByExtension or http.DetectContentType from the standard library or use third-party libmagic bindings, e.g. magicmime.

like image 112
nemo Avatar answered Oct 12 '22 09:10

nemo