Exemplo n.º 1
0
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)
}
Exemplo n.º 2
0
func Append(ctx *godzilla.Context) {
	id, _ := ctx.Replace("url", map[string]interface{}{"url": ctx.Splat[1]})
	ctx.Write(fmt.Sprintf("/url/%d", id))
}