switch to mimemagic to avoid cgo

This commit is contained in:
andreimarcu 2015-09-28 21:41:07 -04:00
parent 56e305bfcc
commit 2255716c7d
2 changed files with 6 additions and 12 deletions

View File

@ -6,8 +6,8 @@ import (
"path" "path"
"strings" "strings"
"bitbucket.org/taruti/mimemagic"
"github.com/flosch/pongo2" "github.com/flosch/pongo2"
"github.com/rakyll/magicmime"
"github.com/zenazn/goji/web" "github.com/zenazn/goji/web"
) )
@ -21,17 +21,12 @@ func fileDisplayHandler(c web.C, w http.ResponseWriter, r *http.Request) {
return return
} }
if err := magicmime.Open(magicmime.MAGIC_MIME_TYPE | file, _ := os.Open(filePath)
magicmime.MAGIC_SYMLINK | header := make([]byte, 512)
magicmime.MAGIC_ERROR); err != nil { file.Read(header)
oopsHandler(c, w, r) file.Close()
}
defer magicmime.Close()
mimetype, err := magicmime.TypeByFile(filePath) mimetype := mimemagic.Match("", header)
if err != nil {
oopsHandler(c, w, r)
}
var tpl *pongo2.Template var tpl *pongo2.Template

View File

@ -81,7 +81,6 @@ func setup() {
goji.Get(nameRe, fileDisplayHandler) goji.Get(nameRe, fileDisplayHandler)
goji.Get(selifRe, fileServeHandler) goji.Get(selifRe, fileServeHandler)
goji.NotFound(notFoundHandler) goji.NotFound(notFoundHandler)
} }
func main() { func main() {