Ejemplo n.º 1
0
func searchListTagsHandler(rr repository.TagRepository) func(http.ResponseWriter, *http.Request) {
	return func(w http.ResponseWriter, r *http.Request) {

		vars := mux.Vars(r)
		term := vars["term"]

		log.Printf("term:" + term)

		tags, err := rr.SearchByTerm(term)
		if err != nil {
			http.Error(w, "Internal server error", http.StatusInternalServerError)
			return
		}
		tagsJson, err := json.Marshal(tags)
		if err != nil {
			http.Error(w, "Internal server error", http.StatusInternalServerError)
			return
		}
		w.Header().Set("Content-Type", "application/json")
		w.Write(tagsJson)
	}
}