-
Notifications
You must be signed in to change notification settings - Fork 80
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
Input validation in separated file #7
Comments
u mean use custom validator.go file to replace all the validator package right? |
Maybe we could put it in same command file and replacing type CreateProduct struct {
ProductID uuid.UUID
Name string
Description string
Price float64
CreatedAt time.Time
}
func NewCreateProduct(name string, description string, price float64) (*CreateProduct, error) {
command := &CreateProduct{
ProductID: uuid.NewV4(),
Name: name,
Description: description,
Price: price,
CreatedAt: time.Now(),
}
err := validator.Validate(command)
if err != nil {
return nil, err
}
return command, nil
}
// using ozzo
func (c *CreateProduct) Validate() error {
return validation.ValidateStruct(&c,
validation.Field(&c.ProductID, validation.Required),
validation.Field(&c.Name, validation.Required, validation.Length(3, 255)),
///...
)
} If you like, feel free to contribute. |
thank you for the tips, let me see what I can do . |
You're welcome :) |
I've already made some changes on command/query level, could you please review them before I go further? btw it seems like I don't have permission to create new branch/ create PR. @mehdihadeli |
Yes, sure. Did you fork the project? You should put your changes in your fork, and after that you can send a pull request to my main branch. Please follow contribution guide. |
Currently, I use tags for validating inputs with go-playground/validator package, maybe it's cleaner that we move them to
validator.go
file in each slice.The text was updated successfully, but these errors were encountered: