DRY up api module

This commit is contained in:
Dan Sosedoff
2015-05-02 20:32:16 -05:00
parent cb3c3e0e2e
commit 04fe0023b7
2 changed files with 21 additions and 59 deletions

View File

@@ -79,8 +79,17 @@ func serveStaticAsset(path string, c *gin.Context) {
data, err := data.Asset("static" + path)
if err != nil {
c.String(400, err.Error())
c.Abort()
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)
}