Skip to content

Commit

Permalink
Merge pull request #455 from nextmv-io/merschformann/osrm-exclude-sup…
Browse files Browse the repository at this point in the history
…port

Enhanced OSRM Client with Exclude Parameter Support
  • Loading branch information
merschformann authored May 21, 2024
2 parents fd7f5dc + f31c179 commit 927990f
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions measure/osrm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,14 @@ func (c *client) tableRequests( //nolint:gocyclo
return nil, err
}

// Determine the information to return. If neither distance nor
// duration is requested, we return both.
isDefault := !config.withDistance && !config.withDuration
annotations := []string{}
if config.withDuration {
if isDefault || config.withDuration {
annotations = append(annotations, "duration")
}

if config.withDistance {
if isDefault || config.withDistance {
annotations = append(annotations, "distance")
}

Expand All @@ -387,6 +389,11 @@ func (c *client) tableRequests( //nolint:gocyclo
path += strings.Join(approaches, ";")
}

if len(config.withExclude) > 0 {
path += "&exclude="
path += strings.Join(config.withExclude, ",")
}

// Set scale factor. This only has an effect on durations.
if c.scaleFactor != 1.0 {
path += fmt.Sprintf("&scale_factor=%f", c.scaleFactor)
Expand Down Expand Up @@ -453,6 +460,7 @@ type tableConfig struct {
withDuration bool
parallelRuns int
withApproachCurb bool
withExclude []string
}

// WithDuration returns a TableOptions function for composing a tableConfig with
Expand Down Expand Up @@ -481,6 +489,14 @@ func WithApproachCurb() TableOptions {
}
}

// WithExclude returns a TableOptions func for a tableConfig with the exclude
// parameter set.
func WithExclude(exclude []string) TableOptions {
return func(c *tableConfig) {
c.withExclude = exclude
}
}

// ClientOption can pass options to be used with an OSRM client.
type ClientOption func(*client)

Expand Down

0 comments on commit 927990f

Please sign in to comment.