Define a MIME_TYPES string map to hold all used mime types
This commit is contained in:
parent
028ef449dc
commit
3f8688fb73
19
api.go
19
api.go
@ -9,19 +9,22 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var MIME_TYPES = map[string]string{
|
||||||
|
".css": "text/css",
|
||||||
|
".js": "application/javascript",
|
||||||
|
".icon": "image-x-icon",
|
||||||
|
}
|
||||||
|
|
||||||
type Error struct {
|
type Error struct {
|
||||||
Message string `json:"error"`
|
Message string `json:"error"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func assetContentType(name string) string {
|
func assetContentType(name string) string {
|
||||||
switch filepath.Ext(name) {
|
mime := MIME_TYPES[filepath.Ext(name)]
|
||||||
case ".css":
|
|
||||||
return "text/css"
|
if mime != "" {
|
||||||
case ".js":
|
return mime
|
||||||
return "application/javascript"
|
} else {
|
||||||
case ".icon":
|
|
||||||
return "image/x-icon"
|
|
||||||
default:
|
|
||||||
return "text/plain"
|
return "text/plain"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user