-
Notifications
You must be signed in to change notification settings - Fork 499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix paging #192
fix paging #192
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks solid!
added some comments/questions, nothing major.
support/url/main.go
Outdated
if err != nil { | ||
return | ||
} | ||
return URL(*gu), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should not be returning specific values if this function has named return values.
|
||
// String encodes all URL segments to a fully qualified URL string | ||
func (u URL) String() string { | ||
gu := gUrl.URL(u) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we not just call u.String()? -- i.e. maybe just leave off this method altogether?
if not -- return gUrl.URL(u).String()
, doesn't need the passthrough var gu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to do that, you'd need to convert the sURL into a gURL every-time you want to call it...
Adding a passthrough gives the following error:
# github.com/stellar/go/support/url
../../../support/url/main.go:24:21: cannot call pointer method on url.URL(*u)
../../../support/url/main.go:24:21: cannot take the address of url.URL(*u)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe @nullstyle or one of the golang experts can weigh in on this.
q := gu.Query() | ||
q.Del(key) | ||
q.Add(key, val) | ||
gu.RawQuery = q.Encode() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need to call q.Encode() here, will it still work if we just delete this line?
it seems hacky to override gu.RawQuery
, almost like we're setting values on gu
twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RawQuery
is a string. The Query()
function decodes current RawQuery
string and returns a Values
struct. I don't see another way to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what I'm suggesting is -- is gu.RawQuery = q.Encode()
a nop here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, unfortunately this is how the URL
struct is built
newUrl := action.BaseURL() // preserve scheme and host for the new url links | ||
newUrl.RawQuery = action.R.URL.RawQuery //preserve query parameters | ||
newUrl.Path = action.Path() //preserve path | ||
newUrl := action.FullURL() // preserve scheme and host for the new url links |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for a cleaner code pattern
ht.Assert.Equal(("http://localhost" + kase.wantSelf), links.Self.Href) | ||
ht.Assert.Equal(("http://localhost" + kase.wantPrevious), links.Prev.Href) | ||
ht.Assert.Equal(("http://localhost" + kase.wantNext), links.Next.Href) | ||
ht.Assert.EqualUrlStrings("http://localhost" + kase.wantSelf, links.Self.Href) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you have gofmt
enabled on save? --that would have removed the " "
around the +
here, which is why I had the ()
@@ -88,5 +87,5 @@ func (action *AssetsAction) loadPage() { | |||
if action.AssetIssuer != "" { | |||
linkParams.Set("asset_issuer", action.AssetIssuer) | |||
} | |||
action.Page.PopulateLinksWithParams(linkParams) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should also remove the linkParams
var here since it's no longer used --your compiler should have issued warning about this?
services/horizon/internal/action.go
Outdated
return result | ||
} | ||
|
||
// BaseURL returns the base url for this request, defined as a url containing | ||
// the Host and Scheme portions of the request uri. | ||
func (action *Action) BaseURL() *url.URL { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if FullURL
is the only consumer of BaseURL
now then we should lowercase this method name.
@@ -39,37 +41,40 @@ type Links struct { | |||
type Page struct { | |||
Links Links `json:"_links"` | |||
BasePage | |||
BasePath string `json:"-"` | |||
//BasePath string `json:"-"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete instead of commenting out
rec := p.Embedded.Records | ||
|
||
//verify paging params | ||
selfUrl := sUrl.URL(*p.FullURL). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't think you need the *
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like there's still some comments you may be working through, let me know when to re-review.
q := gu.Query() | ||
q.Del(key) | ||
q.Add(key, val) | ||
gu.RawQuery = q.Encode() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what I'm suggesting is -- is gu.RawQuery = q.Encode()
a nop here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
See the one travis failure before merging. |
@nullstyle I went ahead and merged this. When your table clears you can take a look to see if you have some feedback from an idiomatic perspective. not urgent at all. |
fix error introduces in #192
@@ -1,13 +1,15 @@ | |||
package hal | |||
|
|||
import ( | |||
sUrl "github.com/stellar/go/support/url" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
package names should always be lower cased: https://blog.golang.org/package-names
We should do the same with our aliases, IMO
gu := gUrl.URL(u) | ||
q := gu.Query() | ||
q.Del(key) | ||
q.Add(key, val) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of using Del
then Add
, just use Set
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
) | ||
|
||
// URL wraps around the native golang URL struct to allow for custom methods | ||
type URL gUrl.URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really happy with this whole type. Go isn't an object-oriented language and this smells too much like you're trying to derive a subtype of URL so you can override some methods. Instead of pretending this type is a URL
lets call this type a URLBuilder
and lets have it wrap a url.URL
, not alias it.
See https://github.com/lann/builder for a pretty well worn implementation of the fluent builder pattern you are proposing here.
apply query filters on paging links. closes #148
also: