func deleteJobs(w rest.ResponseWriter, r *rest.Request) { s := r.PathParam("id") id, err := strconv.Atoi(s) if err != nil { return } RemoveJob(id) w.WriteHeader(http.StatusOK) }
func putJobs(w rest.ResponseWriter, r *rest.Request) { s := r.PathParam("id") id, err := strconv.Atoi(s) if err != nil { return } model := payload(w, r) if model == nil { return } UpdateJob(id, model.Name, model.Expression, model.Command) model.Id = id w.WriteJson(model) }
func payload(w rest.ResponseWriter, r *rest.Request) *JobModel { model := &JobModel{} err := r.DecodeJsonPayload(model) if err != nil { rest.Error(w, err.Error(), http.StatusInternalServerError) return nil } if model.Name == "" { rest.Error(w, "job name required", 400) return nil } if model.Command == "" { rest.Error(w, "job command required", 400) return nil } if model.Expression == "" { rest.Error(w, "job expression required", 400) return nil } return model }