Example #1
0
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)
}
Example #2
0
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)
}
Example #3
0
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)
}
Example #4
0
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)
}