From 2255716c7d70dc9b366e88010e2cf5dec96099c1 Mon Sep 17 00:00:00 2001 From: andreimarcu Date: Mon, 28 Sep 2015 21:41:07 -0400 Subject: [PATCH] switch to mimemagic to avoid cgo --- display.go | 17 ++++++----------- server.go | 1 - 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/display.go b/display.go index 2fe5481..7092d2c 100644 --- a/display.go +++ b/display.go @@ -6,8 +6,8 @@ import ( "path" "strings" + "bitbucket.org/taruti/mimemagic" "github.com/flosch/pongo2" - "github.com/rakyll/magicmime" "github.com/zenazn/goji/web" ) @@ -21,17 +21,12 @@ func fileDisplayHandler(c web.C, w http.ResponseWriter, r *http.Request) { return } - if err := magicmime.Open(magicmime.MAGIC_MIME_TYPE | - magicmime.MAGIC_SYMLINK | - magicmime.MAGIC_ERROR); err != nil { - oopsHandler(c, w, r) - } - defer magicmime.Close() + file, _ := os.Open(filePath) + header := make([]byte, 512) + file.Read(header) + file.Close() - mimetype, err := magicmime.TypeByFile(filePath) - if err != nil { - oopsHandler(c, w, r) - } + mimetype := mimemagic.Match("", header) var tpl *pongo2.Template diff --git a/server.go b/server.go index 81da18e..2a95927 100644 --- a/server.go +++ b/server.go @@ -81,7 +81,6 @@ func setup() { goji.Get(nameRe, fileDisplayHandler) goji.Get(selifRe, fileServeHandler) goji.NotFound(notFoundHandler) - } func main() {