31 lines
		
	
	
		
			592 B
		
	
	
	
		
			Go
		
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			592 B
		
	
	
	
		
			Go
		
	
	
	
package api
 | 
						|
 | 
						|
import (
 | 
						|
	"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]
 | 
						|
 | 
						|
	featureCollection, err := h.geoService.Autocomplete(text)
 | 
						|
	if err != nil {
 | 
						|
		w.WriteHeader(http.StatusInternalServerError)
 | 
						|
		return
 | 
						|
	}
 | 
						|
 | 
						|
	j, err := featureCollection.MarshalJSON()
 | 
						|
	if err != nil {
 | 
						|
		w.WriteHeader(http.StatusInternalServerError)
 | 
						|
		return
 | 
						|
	}
 | 
						|
 | 
						|
	w.Header().Set("Content-Type", "application/json")
 | 
						|
	w.WriteHeader(http.StatusOK)
 | 
						|
	w.Write(j)
 | 
						|
} |