more macaroon stuff

This commit is contained in:
Torkel Ödegaard
2014-10-07 11:53:25 -04:00
parent 222319d924
commit e84f06b503
17 changed files with 343 additions and 11 deletions
+28
View File
@@ -21,6 +21,10 @@ type Context struct {
IsSigned bool
}
func (c *Context) GetAccountId() int {
return c.Account.Id
}
func GetContextHandler() macaron.Handler {
return func(c *macaron.Context, sess session.Store) {
ctx := &Context{
@@ -51,6 +55,30 @@ func (ctx *Context) Handle(status int, title string, err error) {
ctx.HTML(status, "index")
}
func (ctx *Context) ApiError(status int, message string, err error) {
resp := make(map[string]interface{})
if err != nil {
log.Error(4, "%s: %v", message, err)
if macaron.Env != macaron.PROD {
resp["error"] = err
}
}
switch status {
case 404:
resp["message"] = "Not Found"
case 500:
resp["message"] = "Internal Server Error"
}
if message != "" {
resp["message"] = message
}
ctx.HTML(status, "index")
}
func (ctx *Context) JsonBody(model interface{}) bool {
b, _ := ioutil.ReadAll(ctx.Req.Body)
err := json.Unmarshal(b, &model)