Skip to content
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

Support extending model with anonymous field #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

davidfou
Copy link

@davidfou davidfou commented May 1, 2017

Hi,

First, I'm a beginner with Golang. Maybe I didn't respect best practices, you should double check my PR.

The idea is to support fields added my composing a struct with an anonymous field. Here is an example with encoding/json package.

Instead of making it implicit, a new tag attribute extend is added to declare an anonymous field as an extension of the current struct

type Base struct {
	CreatedAt time.Time `jsonapi:"attr,created_at"`
	UpdatedAt time.Time `jsonapi:"updated_at"`
}

type Blog struct {
	Base      `jsonapi:"extend"`
	ID        int       `jsonapi:"primary,blogs"`
	Title     string    `jsonapi:"attr,title"`
	ViewCount int       `jsonapi:"attr,view_count"`

}

Also, the code about model reflection was duplicated in request.go and response.go. It's now factorized in helper.go and it's used constants (no more like this one).

@davidfou davidfou changed the title Support extending model with anonymousField Support extending model with anonymous field May 1, 2017
@davidfou
Copy link
Author

Someone here?

@svperfecta
Copy link

hey @DFournier looks like you're addressing #21 right?

@svperfecta
Copy link

Also, how do you like this vs. #78

@davidfou
Copy link
Author

@genexp sure, this PR is related to #21. The only difference is the new the tag extend which makes it explicit.

#78 looks like to address the same issue except it breaks the API.

@svperfecta
Copy link

svperfecta commented May 15, 2017 via email

@davidfou
Copy link
Author

davidfou commented May 15, 2017

Also, I don't think the field must be anonymous in order to support the extend tag.

About meta, why not! Maybe the lib should handle both in order to not introduce a breaking change but log a depreciation warning about the usage of Meta interface? I don't know the golang library best practices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants