32 lines
596 B
Go
32 lines
596 B
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
func (h *Handler) GeoAutocomplete(w http.ResponseWriter, r *http.Request) {
|
|
t, ok := r.URL.Query()["text"]
|
|
if !ok || len(t[0]) < 1 {
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
text := t[0]
|
|
|
|
result, err := h.geoService.Autocomplete(text)
|
|
if err != nil {
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
j, err := json.Marshal(result.Features)
|
|
if err != nil {
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(http.StatusOK)
|
|
w.Write(j)
|
|
} |