Skip to content
This repository has been archived by the owner on Mar 12, 2023. It is now read-only.

requests can be validated within the struct using the validator. #4

Open
omrfrkazt opened this issue Jan 19, 2023 · 2 comments
Open

Comments

@omrfrkazt
Copy link

func validateCreatePostRequest(req *api.CreatePostRequest) error {

validator : https://github.com/go-playground/validator

@usirin
Copy link
Member

usirin commented Jan 30, 2023

@omrfrkazt can you give a little bit more information on why we need this? I know you are giving this as a suggestion, but not sure what are the pros/cons. Can you talk more on how you used it before?

@omrfrkazt
Copy link
Author

omrfrkazt commented Jan 31, 2023

Pros:
Instead of defining all requests or responses chained validate functions, it makes this part more specific. for example, when the 'required' tag is used, it can automatically validate that field or by writing custom tags for custom validations, the same validation function can be used in many places.

Cons:
Friends who will develop the application need to know what the tags mean. documentation is good but dependency is dependency.

the example in this looks good :
https://medium.com/tunaiku-tech/go-validator-v10-c7a4f1be37df

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

No branches or pull requests

2 participants