mapbox

package
v0.0.0-...-5607d93 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Geocoder covers forward and reverse geocoding mapbox API
	Geocoder
}

Client covers all Mabpox API

type Context

type Context struct {
	ID        string `json:"id"`
	Text      string `json:"text"`
	Wikidata  string `json:"wikidata"`
	ShortCode string `json:"short_code"`
}

func (Context) MarshalEasyJSON

func (v Context) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Context) MarshalJSON

func (v Context) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Context) UnmarshalEasyJSON

func (v *Context) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Context) UnmarshalJSON

func (v *Context) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type FastHttpClient

type FastHttpClient interface {
	Do(req *fasthttp.Request, resp *fasthttp.Response) error
}

type FastHttpGeocoder

type FastHttpGeocoder struct {
	// contains filtered or unexported fields
}

FastHttpGeocoder is a fasthttp Geocoder implementation

func NewFastHttpGeocoder

func NewFastHttpGeocoder(opts ...Option) *FastHttpGeocoder

func (*FastHttpGeocoder) ForwardGeocode

ReverseGeocode calls geocode/v5 reverse mapbox API thought fasthttp client.

func (*FastHttpGeocoder) ReverseGeocode

ReverseGeocode calls geocode/v5 reverse mapbox API thought fasthttp client.

type Feature

type Feature struct {
	ID          string     `json:"id"`
	Type        string     `json:"type"`
	PlaceType   []string   `json:"place_type"`
	Relevance   float64    `json:"relevance"`
	Properties  Properties `json:"properties"`
	Text        string     `json:"text"`
	PlaceName   string     `json:"place_name"`
	Center      []float64  `json:"center"`
	Geometry    Geometry   `json:"geometry"`
	Address     string     `json:"address"`
	Context     []Context  `json:"context"`
	BoundingBox []float64  `json:"bbox"`
}

func (Feature) MarshalEasyJSON

func (v Feature) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Feature) MarshalJSON

func (v Feature) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Feature) UnmarshalEasyJSON

func (v *Feature) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Feature) UnmarshalJSON

func (v *Feature) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type ForwardGeocodeRequest

type ForwardGeocodeRequest struct {
	//The feature you’re trying to look up.
	//This could be an address, a point of interest name, a city name, etc.
	//When searching for points of interest, it can also be a category name (for example, “coffee shop”).
	//For information on categories, see the Point of interest category coverage section.
	//The search text should be expressed as a URL-encoded UTF-8 string,
	//and must not contain the semicolon character (either raw or URL-encoded).
	//Your search text, once decoded, must consist of at most 20 words and numbers separated by spacing and punctuation,
	//and at most 256 characters.
	//
	//The accuracy of coordinates returned by a forward geocoding request can be impacted
	//by how the addresses in the query are formatted. Learn more about address formatting
	//best practices in the https://docs.mapbox.com/help/troubleshooting/address-geocoding-format-guide.
	SearchText string

	//Specify whether to return autocomplete results (true, default) or not (false).
	//When autocomplete is enabled, results will be included that start with the requested string,
	//rather than just responses that match it exactly.
	//For example, a query for India might return both India and Indiana with autocomplete enabled,
	//but only India if it’s disabled.
	//
	//When autocomplete is enabled, each user keystroke counts as one request to the Geocoding API.
	//For example, a search for "coff" would be reflected as four separate Geocoding API requests.
	//To reduce the total requests sent, you can configure your application
	//to only call the Geocoding API after a specific number of characters are typed.
	Autocomplete *bool // default true

	//Limit results to only those contained within the supplied bounding box
	//Bounding boxes should be supplied as four numbers separated by commas,
	//in  minLon,minLat,maxLon,maxLat order.
	//The bounding box cannot cross the 180th meridian.
	Bbox []float64

	//Limit results to one or more countries.
	//Permitted values are ISO 3166 alpha 2 country codes separated by commas.
	Country string

	//Specify whether the Geocoding API should attempt approximate,
	//as well as exact, matching when performing searches (true, default),
	//or whether it should opt out of this behavior and only attempt exact matching (false).
	//For example, the default setting might return Washington, DC for a query of wahsington,
	//even though the query was misspelled.
	FuzzyMatch *bool // default true

	//Specify the user’s language.
	//This parameter controls the language of the text supplied in responses, and also affects result scoring,
	//with results matching the user’s query in the requested language being preferred over results
	//that match in another language. For example, an autocomplete query for things
	//that start with Frank might return Frankfurt as the first result with an English (en) language parameter,
	//but Frankreich (“France”) with a German (de) language parameter.
	//
	//Options are IETF language tags comprised of a mandatory ISO 639-1 language code and, optionally,
	//one or more IETF subtags for country or script.
	//
	//More than one value can also be specified, separated by commas,
	//for applications that need to display labels in multiple languages.
	//
	//For more information on which specific languages are supported, see the https://docs.mapbox.com/api/search/#language-coverage.
	Language string

	//Specify the maximum number of results to return. The default is 5 and the maximum supported is 10.
	Limit int // default 5

	//Bias the response to favor results that are closer to this location
	Proximity *GeoPoint

	//Specify whether to request additional metadata about the recommended navigation destination
	//corresponding to the feature (true) or not (false, default). Only applicable for address features.
	//
	//For example, if routing=true the response could include data about a point on the road the feature fronts.
	//Response features may include an array containing one or more routable points.
	//Routable points cannot always be determined.
	//Consuming applications should fall back to using the feature’s normal geometry for routing
	//if a separate routable point is not returned.
	Routing bool //default false

	//Filter results to include only a subset (one or more) of the available feature types.
	//Options are country, region, postcode, district, place, locality, neighborhood, address, and poi.
	//Multiple options can be comma-separated. Note that poi.landmark is a deprecated type that,
	//while still supported, returns the same data as is returned using the poi type.
	//
	//For more information on the available types, see the https://docs.mapbox.com/api/search/#data-types.
	Types []string
}

type GeoPoint

type GeoPoint struct {
	Lon float64
	Lat float64
}

type GeocodeResponse

type GeocodeResponse struct {
	RateLimit RateLimit
	// Raw mapbox API response
	RawResp []byte
	// passed query to mapbox
	ReverseQuery GeoPoint
	ForwardQuery []string
	// response result type
	Type string
	// response data
	Features []Feature
}

GeocodeResponse

type Geocoder

type Geocoder interface {
	// ReverseGeocode calls geocode/v5 reverse mapbox API
	ReverseGeocode(ctx context.Context, req *ReverseGeocodeRequest) (*GeocodeResponse, error)
	// ReverseGeocode calls geocode/v5 reverse mapbox API
	ForwardGeocode(ctx context.Context, req *ForwardGeocodeRequest) (*GeocodeResponse, error)
}

Geocoder encapsulates forward and reverse geocode calls.

type GeocoderMock

type GeocoderMock struct {
	ForwardGeocodeMock mGeocoderMockForwardGeocode

	ReverseGeocodeMock mGeocoderMockReverseGeocode
	// contains filtered or unexported fields
}

GeocoderMock implements Geocoder

func NewGeocoderMock

func NewGeocoderMock(t minimock.Tester) *GeocoderMock

NewGeocoderMock returns a mock for Geocoder

func (*GeocoderMock) ForwardGeocode

func (mmForwardGeocode *GeocoderMock) ForwardGeocode(ctx context.Context, req *ForwardGeocodeRequest) (gp1 *GeocodeResponse, err error)

ForwardGeocode implements Geocoder

func (*GeocoderMock) ForwardGeocodeAfterCounter

func (mmForwardGeocode *GeocoderMock) ForwardGeocodeAfterCounter() uint64

ForwardGeocodeAfterCounter returns a count of finished GeocoderMock.ForwardGeocode invocations

func (*GeocoderMock) ForwardGeocodeBeforeCounter

func (mmForwardGeocode *GeocoderMock) ForwardGeocodeBeforeCounter() uint64

ForwardGeocodeBeforeCounter returns a count of GeocoderMock.ForwardGeocode invocations

func (*GeocoderMock) MinimockFinish

func (m *GeocoderMock) MinimockFinish()

MinimockFinish checks that all mocked methods have been called the expected number of times

func (*GeocoderMock) MinimockForwardGeocodeDone

func (m *GeocoderMock) MinimockForwardGeocodeDone() bool

MinimockForwardGeocodeDone returns true if the count of the ForwardGeocode invocations corresponds the number of defined expectations

func (*GeocoderMock) MinimockForwardGeocodeInspect

func (m *GeocoderMock) MinimockForwardGeocodeInspect()

MinimockForwardGeocodeInspect logs each unmet expectation

func (*GeocoderMock) MinimockReverseGeocodeDone

func (m *GeocoderMock) MinimockReverseGeocodeDone() bool

MinimockReverseGeocodeDone returns true if the count of the ReverseGeocode invocations corresponds the number of defined expectations

func (*GeocoderMock) MinimockReverseGeocodeInspect

func (m *GeocoderMock) MinimockReverseGeocodeInspect()

MinimockReverseGeocodeInspect logs each unmet expectation

func (*GeocoderMock) MinimockWait

func (m *GeocoderMock) MinimockWait(timeout mm_time.Duration)

MinimockWait waits for all mocked methods to be called the expected number of times

func (*GeocoderMock) ReverseGeocode

func (mmReverseGeocode *GeocoderMock) ReverseGeocode(ctx context.Context, req *ReverseGeocodeRequest) (gp1 *GeocodeResponse, err error)

ReverseGeocode implements Geocoder

func (*GeocoderMock) ReverseGeocodeAfterCounter

func (mmReverseGeocode *GeocoderMock) ReverseGeocodeAfterCounter() uint64

ReverseGeocodeAfterCounter returns a count of finished GeocoderMock.ReverseGeocode invocations

func (*GeocoderMock) ReverseGeocodeBeforeCounter

func (mmReverseGeocode *GeocoderMock) ReverseGeocodeBeforeCounter() uint64

ReverseGeocodeBeforeCounter returns a count of GeocoderMock.ReverseGeocode invocations

type GeocoderMockForwardGeocodeExpectation

type GeocoderMockForwardGeocodeExpectation struct {
	Counter uint64
	// contains filtered or unexported fields
}

GeocoderMockForwardGeocodeExpectation specifies expectation struct of the Geocoder.ForwardGeocode

func (*GeocoderMockForwardGeocodeExpectation) Then

Then sets up Geocoder.ForwardGeocode return parameters for the expectation previously defined by the When method

type GeocoderMockForwardGeocodeParams

type GeocoderMockForwardGeocodeParams struct {
	// contains filtered or unexported fields
}

GeocoderMockForwardGeocodeParams contains parameters of the Geocoder.ForwardGeocode

type GeocoderMockForwardGeocodeResults

type GeocoderMockForwardGeocodeResults struct {
	// contains filtered or unexported fields
}

GeocoderMockForwardGeocodeResults contains results of the Geocoder.ForwardGeocode

type GeocoderMockReverseGeocodeExpectation

type GeocoderMockReverseGeocodeExpectation struct {
	Counter uint64
	// contains filtered or unexported fields
}

GeocoderMockReverseGeocodeExpectation specifies expectation struct of the Geocoder.ReverseGeocode

func (*GeocoderMockReverseGeocodeExpectation) Then

Then sets up Geocoder.ReverseGeocode return parameters for the expectation previously defined by the When method

type GeocoderMockReverseGeocodeParams

type GeocoderMockReverseGeocodeParams struct {
	// contains filtered or unexported fields
}

GeocoderMockReverseGeocodeParams contains parameters of the Geocoder.ReverseGeocode

type GeocoderMockReverseGeocodeResults

type GeocoderMockReverseGeocodeResults struct {
	// contains filtered or unexported fields
}

GeocoderMockReverseGeocodeResults contains results of the Geocoder.ReverseGeocode

type Geometry

type Geometry struct {
	Type        string    `json:"type"`
	Coordinates []float64 `json:"coordinates"`
}

func (Geometry) MarshalEasyJSON

func (v Geometry) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Geometry) MarshalJSON

func (v Geometry) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Geometry) UnmarshalEasyJSON

func (v *Geometry) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Geometry) UnmarshalJSON

func (v *Geometry) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Logger

type Logger interface {
	Debugf(msg string, params ...interface{})
	Errorf(msg string, params ...interface{})
}

type LoggerMock

type LoggerMock struct {
	DebugfMock mLoggerMockDebugf

	ErrorfMock mLoggerMockErrorf
	// contains filtered or unexported fields
}

LoggerMock implements Logger

func NewLoggerMock

func NewLoggerMock(t minimock.Tester) *LoggerMock

NewLoggerMock returns a mock for Logger

func (*LoggerMock) Debugf

func (mmDebugf *LoggerMock) Debugf(msg string, params ...interface{})

Debugf implements Logger

func (*LoggerMock) DebugfAfterCounter

func (mmDebugf *LoggerMock) DebugfAfterCounter() uint64

DebugfAfterCounter returns a count of finished LoggerMock.Debugf invocations

func (*LoggerMock) DebugfBeforeCounter

func (mmDebugf *LoggerMock) DebugfBeforeCounter() uint64

DebugfBeforeCounter returns a count of LoggerMock.Debugf invocations

func (*LoggerMock) Errorf

func (mmErrorf *LoggerMock) Errorf(msg string, params ...interface{})

Errorf implements Logger

func (*LoggerMock) ErrorfAfterCounter

func (mmErrorf *LoggerMock) ErrorfAfterCounter() uint64

ErrorfAfterCounter returns a count of finished LoggerMock.Errorf invocations

func (*LoggerMock) ErrorfBeforeCounter

func (mmErrorf *LoggerMock) ErrorfBeforeCounter() uint64

ErrorfBeforeCounter returns a count of LoggerMock.Errorf invocations

func (*LoggerMock) MinimockDebugfDone

func (m *LoggerMock) MinimockDebugfDone() bool

MinimockDebugfDone returns true if the count of the Debugf invocations corresponds the number of defined expectations

func (*LoggerMock) MinimockDebugfInspect

func (m *LoggerMock) MinimockDebugfInspect()

MinimockDebugfInspect logs each unmet expectation

func (*LoggerMock) MinimockErrorfDone

func (m *LoggerMock) MinimockErrorfDone() bool

MinimockErrorfDone returns true if the count of the Errorf invocations corresponds the number of defined expectations

func (*LoggerMock) MinimockErrorfInspect

func (m *LoggerMock) MinimockErrorfInspect()

MinimockErrorfInspect logs each unmet expectation

func (*LoggerMock) MinimockFinish

func (m *LoggerMock) MinimockFinish()

MinimockFinish checks that all mocked methods have been called the expected number of times

func (*LoggerMock) MinimockWait

func (m *LoggerMock) MinimockWait(timeout mm_time.Duration)

MinimockWait waits for all mocked methods to be called the expected number of times

type LoggerMockDebugfExpectation

type LoggerMockDebugfExpectation struct {
	Counter uint64
	// contains filtered or unexported fields
}

LoggerMockDebugfExpectation specifies expectation struct of the Logger.Debugf

type LoggerMockDebugfParams

type LoggerMockDebugfParams struct {
	// contains filtered or unexported fields
}

LoggerMockDebugfParams contains parameters of the Logger.Debugf

type LoggerMockErrorfExpectation

type LoggerMockErrorfExpectation struct {
	Counter uint64
	// contains filtered or unexported fields
}

LoggerMockErrorfExpectation specifies expectation struct of the Logger.Errorf

type LoggerMockErrorfParams

type LoggerMockErrorfParams struct {
	// contains filtered or unexported fields
}

LoggerMockErrorfParams contains parameters of the Logger.Errorf

type Option

type Option func(c config) config

Option allows gradually modify config

func AccessToken

func AccessToken(at string) Option

AccessToken sets access_token get param. Could be set with MAPBOX_ACCESS_TOKEN too.

func GeocodeEndpoint

func GeocodeEndpoint(endpoint string) Option

GeocodeEndpoint sets geocode endpoint. could be set to mapbox.places-permanent, defualt to mapbox.places

func HttpClient

func HttpClient(c FastHttpClient) Option

HttpClient allows to change default fast http client

func Log

func Log(l Logger) Option

Log used to debug traces and to log errors.

func RequestLogger

func RequestLogger(extract func(ctx context.Context) Logger) Option

RequestLogger sets the way testLogger could be extracted from request context. If set will be used instead of Log.

func RootAPI

func RootAPI(rootAPI string) Option

RootAPI allows to change root api address. default to https://api.mapbox.com

type Properties

type Properties struct {
	Accuracy  string `json:"accuracy"`
	ShortCode string `json:"short_code"`
}

func (Properties) MarshalEasyJSON

func (v Properties) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Properties) MarshalJSON

func (v Properties) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Properties) UnmarshalEasyJSON

func (v *Properties) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Properties) UnmarshalJSON

func (v *Properties) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type RateLimit

type RateLimit struct {
	Interval []byte
	Limit    []byte
	Reset    []byte
}

RateLimit wraps mapbox API rate limit resp headers

type ReverseGeocodeRequest

type ReverseGeocodeRequest struct {
	GeoPoint GeoPoint
	// Limit results to one or more countries.
	Limit int
	// Filter results to include only a subset (one or more) of the available feature types.
	// Options are country, region, postcode, district, place, locality, neighborhood, address, and poi.
	// Multiple options can be comma-separated. Note that poi.landmark is a deprecated type that, while still supported,
	// returns the same data as is returned using the poi type.
	Types []string
	// Permitted values are ISO 3166 alpha 2(https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country codes separated by commas.
	Country string
	// Specify the user’s language. This parameter controls the language of the text supplied in responses.
	// Options are IETF language tags comprised of a mandatory ISO 639-1 language code and, optionally,
	// one or more IETF subtags for country or script.
	// More than one value can also be specified, separated by commas,
	// for applications that need to display labels in multiple languages.
	// For more information on which specific languages are supported, see https://docs.mapbox.com/api/search/#language-coverage
	Language string
	// Decides how results are sorted in a reverse geocoding query
	// if multiple results are requested using a limit other than 1.
	// Options are distance (default), which causes the closest feature
	// to always be returned first, and score, which allows high-prominence features
	// to be sorted higher than nearer, lower-prominence features.
	ReverseMode int
	// Specify whether to request additional metadata about the recommended navigation destination corresponding
	// to the feature (true) or not (false, default). Only applicable for address features.
	// For example, if routing=true the response could include data about a point on the road the feature fronts.
	// Response features may include an array containing one or more routable points.
	// Routable points cannot always be determined.
	// Consuming applications should fall back to using the feature’s normal geometry for routing
	// if a separate routable point is not returned.
	Routing bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL