lot of new functionalities
This commit is contained in:
32
servers/web/api/geo.go
Normal file
32
servers/web/api/geo.go
Normal file
@@ -0,0 +1,32 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user