How to check filetype in golang (equlvalent of filetype cmd in linux )
3,256 views
Skip to first unread message
Rahul R
unread,
Aug 10, 2013, 4:40:56 PM8/10/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
Hey guys ,
What is the easiest way to check the filetypes using golang. I shud be able to know, whether its a regualr ascii file or berkely db file or executable. similar to filetype command in golang. How do I check the same ?
Thanks,
./Rahul
Andy Balholm
unread,
Aug 10, 2013, 5:13:38 PM8/10/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golan...@googlegroups.com
You could use the os/exec package to run your system's "file" command.
Or you could find the C source of the "file" command and port it to Go. I think it uses a library called libmagic. Maybe you could link to that with CGO.
Or you could look on godoc.org for Go bindings for libmagic. I think there are at least two. I also see a less exhaustive pure-Go library that uses the http package's content sniffing.
Ibrahim M. Ghazal
unread,
Aug 11, 2013, 7:41:37 AM8/11/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message