Merge "internal/geocode: change Lookup behavior wrt to AltLookupFn"

This commit is contained in:
Mathieu Lonjaret 2018-04-26 02:22:21 +00:00 committed by Gerrit Code Review
commit 11dfa3850d
3 changed files with 7 additions and 7 deletions

View File

@ -49,11 +49,11 @@ type Rect struct {
// AltLookupFn provides alternative geocode lookup in tests.
//
// If AltLookupFn is not nil, Lookup calls AltLookupFn first,
// and returns the results unless it is (nil, nil).
// If AltLookupFn is not nil, Lookup returns the results of
// the AltLookupFn call.
//
// Lookup performs its standard lookup using its cache
// and the Google geocoding serice if AltLookupFn is nil,
// and the Google geocoding service if AltLookupFn is nil,
// or it returns (nil, nil) for the address being looked up.
//
// It's up to the caller to change AltLookupFn only
@ -99,10 +99,7 @@ var ErrNoGoogleKey = errors.New("geocode: geocoding is not configured; see https
// implementation is the Google geocoding service.
func Lookup(ctx context.Context, address string) ([]Rect, error) {
if AltLookupFn != nil {
r, err := AltLookupFn(ctx, address)
if r != nil || err != nil {
return r, err
}
return AltLookupFn(ctx, address)
}
mu.RLock()

View File

@ -48,3 +48,5 @@ func (s *Handler) ExportGetPermanodeLocation(ctx context.Context, permaNode blob
func ExportBestByLocation(res *SearchResult, loc map[blob.Ref]camtypes.Location, limit int) {
bestByLocation(res, loc, limit)
}
var ExportUitdamLC = uitdamLC

View File

@ -1904,6 +1904,7 @@ func init() {
cacheGeo("mexico", 32.7187629, -86.7105711, 14.5345486, -118.3649292)
cacheGeo("brazil", 5.2717863, -29.3448224, -33.7506241, -73.98281709999999)
cacheGeo("argentina", -21.7810459, -53.6374811, -55.05727899999999, -73.56036019999999)
cacheGeo("Uitdam", ExportUitdamLC.North, ExportUitdamLC.East, ExportUitdamLC.South, ExportUitdamLC.West)
geocode.AltLookupFn = func(ctx context.Context, addr string) ([]geocode.Rect, error) {
r, ok := altLocCache[addr]