Documentation
¶
Overview ¶
Package osrm exposes the OSRM (Open Source Routing Machine) demo server as a kit Domain driver. A multi-domain host (ant) enables it with a single blank import:
import _ "github.com/tamnd/osrm-cli/osrm"
The same Domain also builds the standalone osrm binary, so the binary and a host share one source of truth.
Package osrm is the library behind the osrm command line: the HTTP client, request shaping, and the typed data models for the OSRM (Open Source Routing Machine) demo server (router.project-osrm.org).
The client is polite: it sets a real User-Agent, paces requests, and retries transient failures (429 and 5xx). OSRM uses (longitude, latitude) coordinate order in URLs; the public API accepts the more natural (lat, lon) and swaps internally.
Index ¶
Constants ¶
const BaseURL = "http://" + Host
BaseURL is the root every request is built from.
const DefaultUserAgent = "osrm-cli/0.1 (tamnd87@gmail.com)"
DefaultUserAgent identifies the client. Honest, descriptive, contact included.
const Host = "router.project-osrm.org"
Host is the OSRM demo server hostname.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the OSRM demo server over HTTP.
func (*Client) Nearest ¶
func (c *Client) Nearest(ctx context.Context, coord string, count int, mode string) ([]NearestPoint, error)
Nearest finds the nearest road segment(s) to a single "lat,lon" coordinate. count controls how many candidates are returned (default 1).
type Config ¶
type Config struct {
BaseURL string
UserAgent string
Rate time.Duration
Timeout time.Duration
Retries int
}
Config holds all tunable parameters for the Client.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults.
type Domain ¶
type Domain struct{}
Domain is the OSRM driver. It carries no state; the per-run client is built by the factory Register hands to kit.
func (Domain) Info ¶
func (Domain) Info() kit.DomainInfo
Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.
type MatrixRow ¶
type MatrixRow struct {
From int `kit:"id" json:"from"`
To int `json:"to"`
Distance float64 `json:"distance_km"`
Duration float64 `json:"duration_min"`
}
MatrixRow is one cell in the distance/duration matrix.