Refactor mime type detection by using path/filepath package

This commit is contained in:
Dan Sosedoff 2014-11-06 07:21:53 -06:00
parent 338df85549
commit b6d1b2502e

16
api.go
View File

@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"github.com/gin-gonic/gin"
"path/filepath"
"strings"
)
@ -12,20 +13,17 @@ 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"
}
}
func API_Home(c *gin.Context) {
data, err := Asset("static/index.html")