func JSONHandler(ctx wombat.Context, a *articles.Article, imagePath string, data []byte) { // Get the JSONMessage from the request var msg JSONMessage err := json.Unmarshal(data, &msg) if err != nil { ctx.HttpError(http.StatusBadRequest, GetError(ctx.Request, err)) return } // Perform the given action switch msg.Action { default: // Invalid/missing action err = errors.New("Invalid Action") case "setSynopsis": err = a.SetSynopsis(msg.Data) case "setContent": err = a.SetContent(msg.Data) case "setActive": // Toggle err = a.Publish(!a.IsPublished) case "deleteImage": err = RemoveImage(a, msg.Data, imagePath) } // Report if the action resulted in an error if err != nil { ctx.HttpError(http.StatusInternalServerError, GetError(ctx.Request, err)) } }