-
Notifications
You must be signed in to change notification settings - Fork 7
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
Hypermedia responses #13
Conversation
fill sawyer.Response’s Rels on Decode()
@technoweenie The refactoring looks good to me. But we prob. need to pay attention to race condition on the lazily loaded fields, if we're not setting the fields ahead of time at the JSON serialization step. |
Ah good point. I might even take that out since that I also don't intend to support these resource objects used in a shared context. They should be initialized on every request, or passed around in channels. |
This got me thinking though why we're using two approaches to set the relations, one with lazy load, the other with reflection. I would still call the latter approach a DI (dependency injection) one, even though we don't use an library. |
In case my last comment doesn't much sense, we're supposed to use the |
Sorry, serialization => deserialization |
The "HyperField" relations are to support the GitHub API (due to our initial support of |
Ah, ok, I think I'm more clear now. Would you think it makes sense to set both // in Response.Decode
func (r *Response) Decode(resource interface{}) error {
// decode with media type decoder
// fill relations by using HyperFieldRelations and some code from HALResource
} It'll remove the lazy fields loading and make setting the relations consistent at one place: after the JSON deserialization steps. |
That's how it works: https://github.com/lostisland/go-sawyer/pull/13/files#diff-b01558cabf60ed66d8a2c08b2bfaba31R56 Response.fillRels() is called after decoding if there aren't any errors. The Rels() function is no longer needed and can be removed. The goal of this PR is to store the relations in the sawyer.Response, regardless if they come from the header, HAL, or reflected from the resource's fields. |
👍 |
Okay, I removed |
This moves the mediaheader package into hypermedia. Hypermedia is now broken up to separate the different ways of pulling hypermedia for an HTTP response. The resource itself is only checked automatically if it's decoded through the response's media type.
This is written for #12 and should be applied first.