Refactor and simplify asset serving

This commit is contained in:
Dan Sosedoff
2015-05-02 20:10:14 -05:00
parent dd2200bdb8
commit 0ac9d72deb
2 changed files with 16 additions and 25 deletions

View File

@@ -5,6 +5,7 @@ import (
"path/filepath"
"github.com/gin-gonic/gin"
"github.com/sosedoff/pgweb/pkg/data"
)
var extraMimeTypes = map[string]string{
@@ -13,6 +14,7 @@ var extraMimeTypes = map[string]string{
".woff": "application/x-font-woff",
".eot": "application/vnd.ms-fontobject",
".svg": "image/svg+xml",
".html": "text/html; charset-utf-8",
}
type Error struct {
@@ -72,3 +74,13 @@ func dbCheckMiddleware() gin.HandlerFunc {
return
}
}
func serveStaticAsset(path string, c *gin.Context) {
data, err := data.Asset("static" + path)
if err != nil {
c.String(400, err.Error())
c.Abort()
}
c.Data(200, assetContentType(path), data)
}