func Modify(ctx *godzilla.Context) { if !is_admin(ctx) { ctx.Error("not allowed", 404) return } object_id := ctx.Splat[2] object_type := ctx.Splat[1] if object_type != "posts" && object_type != "categories" && object_type != "post_category" { ctx.Error("bad object type", 500) return } var output interface{} switch ctx.R.Method { case "GET": output = ctx.FindById(object_type, object_id) case "POST": var j map[string]interface{} json.Unmarshal([]byte(ctx.Sparams["json"]), &j) if j == nil { j = map[string]interface{}{} } j["updated_at"] = time.Now().Unix() id, _ := ctx.Replace(object_type, j) output = ctx.FindById(object_type, id) case "DELETE": ctx.DeleteById(object_type, object_id) output = "deleted " + object_id + "@" + object_type } ctx.RenderJSON(output, 404) }
func Redirect(ctx *godzilla.Context) { u := ctx.FindById("url", ctx.Splat[1]) if u == nil { ctx.Error("not found", 404) } else { ctx.Redirect(reflect.ValueOf(u["url"]).String()) } }
func Show(ctx *godzilla.Context) { o := ctx.FindById("posts", ctx.Splat[1]) if o == nil { ctx.Error("nothing to do here.. \\o/", 404) return } ctx.O["title"] = o["title"] ctx.O["item"] = o ctx.Render() }