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

@@ -12,20 +12,16 @@ import (
"github.com/sosedoff/pgweb/pkg/client"
"github.com/sosedoff/pgweb/pkg/command"
"github.com/sosedoff/pgweb/pkg/connection"
"github.com/sosedoff/pgweb/pkg/data"
)
var DbClient *client.Client
func GetHome(c *gin.Context) {
data, err := data.Asset("static/index.html")
serveStaticAsset("/index.html", c)
}
if err != nil {
c.String(400, err.Error())
return
}
c.Data(200, "text/html; charset=utf-8", data)
func GetAsset(c *gin.Context) {
serveStaticAsset(c.Params.ByName("path"), c)
}
func GetConnect(c *gin.Context) {
@@ -248,20 +244,3 @@ func GetBookmarks(c *gin.Context) {
c.JSON(200, bookmarks)
}
func GetAsset(c *gin.Context) {
path := "static" + c.Params.ByName("path")
data, err := data.Asset(path)
if err != nil {
c.String(400, err.Error())
return
}
if len(data) == 0 {
c.String(404, "Asset is empty")
return
}
c.Data(200, assetContentType(path), data)
}