perhaps a memory/performance improvement? by not recreating the same function over and over? maybe.

This commit is contained in:
Howl 2016-04-08 17:27:55 +02:00
parent ed2778e2cc
commit e3cb4aed09
1 changed files with 55 additions and 51 deletions

View File

@ -11,6 +11,11 @@ import (
// Method wraps an API method to a HandlerFunc.
func Method(f func(md common.MethodData) common.Response, db *sql.DB, privilegesNeeded ...int) gin.HandlerFunc {
return func(c *gin.Context) {
initialCaretaker(c, f, db, privilegesNeeded...)
}
}
func initialCaretaker(c *gin.Context, f func(md common.MethodData) common.Response, db *sql.DB, privilegesNeeded ...int) {
data, err := ioutil.ReadAll(c.Request.Body)
if err != nil {
c.Error(err)
@ -62,5 +67,4 @@ func Method(f func(md common.MethodData) common.Response, db *sql.DB, privileges
} else {
c.IndentedJSON(resp.Code, resp)
}
}
}