From b6d1b2502e3e38d60926848a6e432e91e5f7dc69 Mon Sep 17 00:00:00 2001 From: Dan Sosedoff Date: Thu, 6 Nov 2014 07:21:53 -0600 Subject: [PATCH] Refactor mime type detection by using path/filepath package --- api.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/api.go b/api.go index 805151f..56e1bd6 100644 --- a/api.go +++ b/api.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "github.com/gin-gonic/gin" + "path/filepath" "strings" ) @@ -12,19 +13,16 @@ type Error struct { } func assetContentType(name string) string { - if strings.Contains(name, ".css") { + switch filepath.Ext(name) { + case ".css": return "text/css" - } - - if strings.Contains(name, ".js") { + case ".js": return "application/javascript" - } - - if strings.Contains(name, ".icon") { + case ".icon": return "image/x-icon" + default: + return "text/plain" } - - return "text/plain" } func API_Home(c *gin.Context) {