gosrm

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2020 License: MIT Imports: 13 Imported by: 0

README

GOSRM - GO Client for OSRM

Build Status godoc License Go Report Card

Advanced OSRM client for golang.

Features

  • Route Client

Installation

go get github.com/karmadon/gosrm

Quick Start

Route Service
package main

import (
	"fmt"
	"net/url"
	"github.com/karmadon/gosrm"
	"github.com/paulmach/go.geo"
)

func main() {
    options := &gosrm.Options{
        Url:            url.URL{Host: "https://router.project-osrm.org/"},
        Service:        consts.ServiceRoute,
        Version:        consts.VersionFirst,
        Profile:        consts.ProfileDriving,
        RequestTimeout: 5,
    }

    client := gosrm.NewClient(options)

    routeRequest := &models.RouteRequest{
        Coordinates: geo.PointSet{{36.232051849365234, 49.98765584451778}, {36.22089385986328, 50.03718650830641}},
    }

    response, err := client.Route(routeRequest)
    if err != nil {
        panic(err.Error())
    }

    fmt.Printf("%#v", response)
}
Table Service
package main

import (
	"fmt"
	"net/url"
	"github.com/karmadon/gosrm"
	"github.com/paulmach/go.geo"
)

func main() {
	options := &gosrm.Options{
		Url:            url.URL{Host: "https://router.project-osrm.org/"},
		Service:        consts.ServiceTable,
		Version:        consts.VersionFirst,
		Profile:        consts.ProfileDriving,
		RequestTimeout: 5,
	}

	client := gosrm.NewClient(options)

	sources := []int{1, 2}
	destinations := []int{2, 1}

	annotation := consts.TableAnnotationDurationDistance
	scaleFactor := 1.2

	tableRequest := &models.TableRequest{
		Coordinates:  geo.PointSet{{36.232051849365234, 49.98765584451778}, {36.22089385986328, 50.03718650830641}},
		Sources:      &sources,
		Destinations: &destinations,
		Annotations:  &annotation,
		ScaleFactor:  &scaleFactor,
	}

	response, err := client.Table(tableRequest)
	if err != nil {
		panic(err.Error())
	}

	fmt.Printf("%#v", response)
}
Full Example

See examples folder

Documentation

Index

Constants

View Source
const CodeOK = "Ok"

Variables

View Source
var RespCode = map[string]string{
	"NoRoute":        "No route found",
	"NoTable":        "No route found in table method.",
	"NoMatch":        "No matching found.",
	"NoTrips":        "No trips found because input coordinates are not connected.",
	"NotImplemented": "This request is not supported",
	"InvalidUrl":     "URL string is invalid",
	"Ok":             "All OK",
	"InvalidService": "Service name is invalid.",
	"InvalidVersion": "OSRM Version is not found.",
	"InvalidOptions": "Options are invalid.",
	"InvalidQuery":   "The query string is syntactically malformed.",
	"InvalidValue":   "The successfully parsed query parameters are invalid.",
	"NoSegment":      "One of the supplied input coordinates could not snap to street segment.",
	"TooBig":         "The request size violates one of the service specific request size restrictions",
}

Errors which could be returned from OSRM Server

Functions

This section is empty.

Types

type GOSRMError added in v0.1.0

type GOSRMError struct {
	Url         *url.URL
	Err         error
	RawResponse *[]byte
}

func NewGOSRMError added in v0.1.0

func NewGOSRMError(url *url.URL, err error, rawResponse *[]byte) *GOSRMError

func (*GOSRMError) Error added in v0.1.0

func (e *GOSRMError) Error() string

type Options

type Options struct {
	// Url of osrm server with / on the end
	Url url.URL `json:"url"`

	// One of the following values:  route ,  nearest ,  table ,  match ,  trip ,  tile
	Service string `json:"service"`

	//	Version of the protocol implemented by the service
	Version string `json:"version"`

	// Mode of transportation, is determined statically by the Lua profile that is used to prepare the data using  osrm-extract
	Profile string `json:"profile"`

	GenerateHints bool `json:"generate_hints"`

	// Timeout for request in seconds
	RequestTimeout int `json:"request_timeout"`

	// if need debug you should turn this on
	Debug bool `json:"debug"`
}

OSRM client options structure

func (*Options) BaseUrl

func (o *Options) BaseUrl() (*url.URL, error)

Gets Base url from options

type OsrmClient

type OsrmClient struct {
	Options *Options
	// contains filtered or unexported fields
}

Osrm Client Object

func NewClient

func NewClient(options *Options) *OsrmClient

NewClient creates a client with options

func (*OsrmClient) Match

func (*OsrmClient) Nearest

func (*OsrmClient) Route

func (*OsrmClient) Table

Directories

Path Synopsis
examples
route command
table command

Jump to

Keyboard shortcuts

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