Adds general options and missing options for table request#13
Adds general options and missing options for table request#13mkasner wants to merge 1 commit intogojuno:masterfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## master #13 +/- ##
==========================================
+ Coverage 96.55% 96.82% +0.27%
==========================================
Files 8 8
Lines 232 252 +20
==========================================
+ Hits 224 244 +20
Misses 4 4
Partials 4 4
Continue to review full report at Codecov.
|
|
Updated code with proposed changes |
4e40b18 to
955d9aa
Compare
There was a problem hiding this comment.
First of all, great job to make types reusable in different requests.
I have a question: how to be with backward compatibility?
My code does the following:
req := osrm.MatchRequest{
Hints: []string{"X","Y"},
}
but new change will break compilation process because I need to change the code:
req := osrm.MatchRequest{
GeneralOptions: osrm.GeneralOptions{
Hints: []string{"X","Y"},
},
}
types.go
Outdated
|
|
||
| const ( | ||
| FallbackCoordinateInput FallbackCoordinate = "input" | ||
| FallbackCoordinateSnapped = "snapped" |
There was a problem hiding this comment.
FallbackCoordinateSnapped FallbackCoordinate as well
There was a problem hiding this comment.
Yes, you are right.
I used this like iota :)
There was a problem hiding this comment.
It doesn't work like iota. You must declare the type explicitly.
https://play.golang.org/p/iVeaitEtA2k
| AnnotationsDatasources Annotations = "datasources" | ||
| AnnotationsWeight Annotations = "weight" | ||
| AnnotationsSpeed Annotations = "speed" | ||
| AnnotationsDurationDistance Annotations = "duration,distance" |
There was a problem hiding this comment.
Why do you need that?
Maybe add a function to combine multiple annotations in a request?
There was a problem hiding this comment.
I can do the function. There's a request in TabeService which combines duration and distance, and returns it in the response. That's the reason I need it.
I thought this would be more simpler, since this is considered like a 3rd option for that param in request.
There was a problem hiding this comment.
I think you could add a function:
func (a Annotations) Concat(b Annotations) Annotations {
return a + "," + b
}
and use it in your code as well:
AnnotationsDuration.Concat(AnnotationsDistance)
There was a problem hiding this comment.
I was thinking, if I add a function which enables to combine multiple annotations, then users of the library can product invalid annotations which cannot be combined.
By defining it like this user is always going to produce valid annotations.
This 'duration,distance' is the only combination in the project osrm docs.
I would create a function, if there were more combinations possible, but since it's only one, I would rather leave it defined as const.
Yes, this cannot be backward compatible, unless I copy params from the embedded struct GeneralOptions to every request. |
I like that PR. But I think maintainers must release a major version of it (for example, v0.2.0) with a notice about the backward-incompatible change. |
I didn't yet added changes you requested, about constants type naming, and function for combining duration and distance |
types.go
Outdated
|
|
||
| const ( | ||
| FallbackCoordinateInput FallbackCoordinate = "input" | ||
| FallbackCoordinateSnapped = "snapped" |
There was a problem hiding this comment.
It doesn't work like iota. You must declare the type explicitly.
https://play.golang.org/p/iVeaitEtA2k
|
Sure, I know that. |
| AnnotationsDatasources Annotations = "datasources" | ||
| AnnotationsWeight Annotations = "weight" | ||
| AnnotationsSpeed Annotations = "speed" | ||
| AnnotationsDurationDistance Annotations = "duration,distance" |
There was a problem hiding this comment.
I think you could add a function:
func (a Annotations) Concat(b Annotations) Annotations {
return a + "," + b
}
and use it in your code as well:
AnnotationsDuration.Concat(AnnotationsDistance)
No description provided.