osrm

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

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

View Source
const BaseURL = "http://" + Host

BaseURL is the root every request is built from.

View Source
const DefaultUserAgent = "osrm-cli/0.1 (tamnd87@gmail.com)"

DefaultUserAgent identifies the client. Honest, descriptive, contact included.

View Source
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 NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

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).

func (*Client) Route

func (c *Client) Route(ctx context.Context, coords []string, mode string) ([]Route, error)

Route finds the driving (or cycling/walking) route between two or more waypoints. coords is a slice of "lat,lon" strings; mode is "driving", "cycling", or "walking".

func (*Client) Table

func (c *Client) Table(ctx context.Context, coords []string, mode string) ([]MatrixRow, error)

Table computes the distance and duration matrix between all provided "lat,lon" coordinates. coords must have at least 2 entries.

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) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns an input into the canonical (type, id).

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.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate returns the live http URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

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.

type NearestPoint

type NearestPoint struct {
	Name     string  `kit:"id" json:"name"`
	Distance float64 `json:"distance_m"`
	Lon      float64 `json:"lon"`
	Lat      float64 `json:"lat"`
}

NearestPoint is the nearest road point to a queried coordinate.

type Route

type Route struct {
	Index    int     `kit:"id"      json:"index"`
	Distance float64 `json:"distance_km"`
	Duration float64 `json:"duration_min"`
	Legs     int     `json:"legs"`
}

Route is one computed route between two or more waypoints.

Jump to

Keyboard shortcuts

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