nidus-sync/resource/geocode.go
Eli Ribble 2d5dca3fb5
Add proxied autocomplete for Stadia
This allows me to make the format consistent and to cache the
intermediate results, which is useful for speed and testing
2026-04-05 21:57:30 +00:00

42 lines
988 B
Go

package resource
import (
"context"
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
"github.com/Gleipnir-Technology/nidus-sync/platform/geocode"
"net/http"
//"github.com/rs/zerolog/log"
)
type geocodeR struct {
router *router
}
type geocodeSuggestion struct {
Detail string `json:"detail"`
Locality string `json:"locality"`
}
func Geocode(r *router) *geocodeR {
return &geocodeR{
router: r,
}
}
func (res *geocodeR) SuggestionList(ctx context.Context, r *http.Request, query QueryParams) ([]*geocodeSuggestion, *nhttp.ErrorWithStatus) {
if query.Query == nil {
return nil, nhttp.NewBadRequest("you must include a query")
}
completions, err := geocode.Autocomplete(ctx, nil, *query.Query)
if err != nil {
return nil, nhttp.NewError("geocode: %w", err)
}
result := make([]*geocodeSuggestion, len(completions))
for i, c := range completions {
result[i] = &geocodeSuggestion{
Detail: c.Detail,
Locality: c.Locality,
}
}
return result, nil
}