Exemplo n.º 1
0
func handleUnitsFilter(w http.ResponseWriter, r *http.Request) {
	series_filter := r.FormValue("series")

	series_match_list := make([]dba.UnitDesc, 0, 2)

	series_filter_list := strings.Split(series_filter, ";")
	for _, series_id := range series_filter_list {
		matches, err := dba.FindUnitsBySeries(series_id)
		if err != nil {
			http.Error(w, err.Error(), 500)
			return
		}

		for _, m := range matches {
			series_match_list = append(series_match_list, m)
		}
	}

	sort.Sort(dba.VcsSorter(series_match_list))

	w.Header().Add("Content-Type", "application/json")
	enc := json.NewEncoder(w)
	err := enc.Encode(series_match_list)
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}
}
Exemplo n.º 2
0
func handleUnitsAll(w http.ResponseWriter, r *http.Request) {
	sort_method := r.FormValue("sort")

	units, err := dba.GetUnits()
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	switch sort_method {
	case "vcs":
		sort.Sort(dba.VcsSorter(units))
	default:
	}

	w.Header().Add("Content-Type", "application/json")
	enc := json.NewEncoder(w)
	err = enc.Encode(units)
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}
}