more macaroon stuff
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user