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
This commit is contained in:
parent
b6cfbee102
commit
2d5dca3fb5
11 changed files with 275 additions and 11 deletions
42
resource/geocode.go
Normal file
42
resource/geocode.go
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
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
|
||||
}
|
||||
|
|
@ -1,14 +1,15 @@
|
|||
package resource
|
||||
|
||||
import (
|
||||
//"github.com/gorilla/schema"
|
||||
// "github.com/gorilla/schema"
|
||||
)
|
||||
|
||||
type QueryParams struct {
|
||||
Limit *int `schema:"limit"`
|
||||
Query *string `schema:"query"`
|
||||
Sort *string `schema:"sort"`
|
||||
Type *string `schema:"type"`
|
||||
Limit *int `schema:"limit"`
|
||||
OrganizationID *int `schema:"org"`
|
||||
Query *string `schema:"query"`
|
||||
Sort *string `schema:"sort"`
|
||||
Type *string `schema:"type"`
|
||||
}
|
||||
|
||||
func (qp QueryParams) SortOrDefault(default_name string, ascending bool) (string, bool) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue