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 postJobs(w rest.ResponseWriter, r *rest.Request) { model := payload(w, r) if model == nil { return } id := AddJob(model.Name, model.Expression, model.Command) model.Id = id w.WriteJson(model) }
func getJobs(w rest.ResponseWriter, r *rest.Request) { jobs := make([]*JobModel, len(Jobs)) i := 0 for id, job := range Jobs { jobs[i] = &JobModel{ Id: id, Name: job.Name, Expression: job.Expression, Command: job.Command, } i++ } w.WriteJson(&jobs) }
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) }