Add test for serverResult func

This commit is contained in:
Dan Sosedoff
2018-11-05 17:07:32 -06:00
parent 9ca959c31c
commit abb143601b
3 changed files with 54 additions and 20 deletions

View File

@@ -10,6 +10,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/sosedoff/pgweb/pkg/data"
"github.com/sosedoff/pgweb/pkg/shared"
)
@@ -139,3 +140,22 @@ func assetContentType(name string) string {
return result
}
func serveStaticAsset(path string, c *gin.Context) {
data, err := data.Asset("static" + path)
if err != nil {
c.String(400, err.Error())
return
}
c.Data(200, assetContentType(path), data)
}
func serveResult(result interface{}, err error, c *gin.Context) {
if err != nil {
c.JSON(400, NewError(err))
return
}
c.JSON(200, result)
}