示例#1
0
func HandleDeleteProgram(s *datastore.Schedule, w http.ResponseWriter, r *http.Request) {
	urlComps := strings.Split(r.URL.Path, "/")
	if len(urlComps) < 2 {
		http.Error(w, "Cannot delete schedule", 400)
		return
	}

	programId := urlComps[1]
	programs, err := s.ListPrograms(1)
	if err != nil {
		http.Error(w, "Error finding programs", 500)
		return
	}

	for i := range programs {
		program := programs[i]
		if program.UUID == programId {
			err := s.DeleteProgram(program)
			if err != nil {
				http.Error(w, "Error deleting program", 500)
			}
			return
		}
	}

	http.Error(w, "Program not found", 404)
}
示例#2
0
func HandleListPrograms(s *datastore.Schedule, w http.ResponseWriter, r *http.Request) {
	programs, err := s.ListPrograms(1)
	if err != nil {
		http.Error(w, "Error retrieving schedule for channel", 500)
		return
	}

	w.Header().Add("Content-Type", "application/json")
	json.NewEncoder(w).Encode(programs)
}