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

Remove the necessity for tag in struct and slice validation #9

Closed
guiferpa opened this issue Apr 10, 2020 · 0 comments
Closed

Remove the necessity for tag in struct and slice validation #9

guiferpa opened this issue Apr 10, 2020 · 0 comments
Labels
different approach Change approach for solutions of problems
Milestone

Comments

@guiferpa
Copy link
Owner

It's a problem how gody works today because of necessity for tags in slice and struct.

An example about how it works today:

type Owner struct {
    Name string `validate:"not_empty"`
}

type Task struct {
    Title       string `validate:"not_empty"`
    Description string `validate:"max_bound=140"`
}

type TaskList struct {
    Owner Owner  `validate:"required"` // It's necessary
    Tasks []Task `validate:"required"` // It's necessary
}

The tag with some value is necessary for validation of fields above (Owner and Tasks).

Take a look at line: https://github.com/guiferpa/gody/blob/master/serialize.go#L49-L53

There is the condition to serialize a field. However today it's just verified if it has a tag with any value or haven't, if it contains tag with some value it'll be serialize but if not it'll be ignored.

The purpose is to make the validation even if there's tag or not. Letting the struct typing more clean like this example below:

...

type TaskList struct {
    Owner Owner  // Tag isn't necessary anymore
    Tasks []Task // Tag isn't necessary anymore
}
@guiferpa guiferpa added this to the v2 milestone Apr 10, 2020
@guiferpa guiferpa added the different approach Change approach for solutions of problems label Apr 10, 2020
guiferpa added a commit that referenced this issue Apr 10, 2020
  It was removed the necessity for validate:"<some-parameter>"
to validate Slice and Structs in others levels.
guiferpa added a commit that referenced this issue Apr 10, 2020
  It was removed the necessity for validate:"<some-parameter>"
to validate Slice and Structs in others levels.
guiferpa added a commit that referenced this issue Apr 10, 2020
  It was removed the necessity for validate:"<some-parameter>"
to validate Slice and Structs in others levels.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
different approach Change approach for solutions of problems
Projects
None yet
Development

No branches or pull requests

1 participant