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

doc: provide more examples for parameter validation #652

Closed
Haswf opened this issue Mar 6, 2023 · 3 comments
Closed

doc: provide more examples for parameter validation #652

Haswf opened this issue Mar 6, 2023 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@Haswf
Copy link
Contributor

Haswf commented Mar 6, 2023

Is your feature request related to a problem? Please describe.

Hertz integrates with go-tagexpr for paramater binding and validation. However, go-tagexpr itself is poorly documented, therefore it becomes difficult for people who are new to hertz to add their first vd tag.

Describe the solution you'd like

I would recommand add examples for the following tags:

  • length validation for string and list len($)>0
  • regex pattern match for string regexp('^\\w*$')"
  • value validation for numertic field $>0
  • validation for pointer field num==nil || num>0
  • validation for enum types type=="hello" || type == "world"
  • custom error message msg:'C must be false when S.A>0'"

I have used these tags extensively in production and these tags should cover a widely range of use cases.
Also, we could provide a example of defining vd tags in idl, this should also helps.

Describe alternatives you've considered

Alternative, we can add these examples to reference if it doesn't fit into the scope of Binding and validate

Additional context

I have been used vd for almost 2 years. I constantly found myself confused and frustared with go-tagexpr's documentation. Hopefully, with these examples, hertz users can get started with vd with much less pain.

@Haswf Haswf changed the title doc: provide more examples for binding and validate doc: provide more examples for parameter validation Mar 6, 2023
@Haswf
Copy link
Contributor Author

Haswf commented Mar 6, 2023

related issue: #632

@Duslia Duslia added the enhancement New feature or request label Mar 7, 2023
@Duslia Duslia assigned FGYFFFF and unassigned FGYFFFF Mar 7, 2023
@Duslia Duslia added the good first issue Good for newcomers label Mar 7, 2023
@Duslia
Copy link
Member

Duslia commented Mar 7, 2023

Could you help to add more examples? @Haswf

@FGYFFFF
Copy link
Contributor

FGYFFFF commented Mar 7, 2023

@Haswf We have refactored the parameter binding and validation capabilities (#541), and the new validation function will use "go-playground/validator".

The "go-tagexpr" will be moved to "hertz-contrib".

You can write a new example after the new version is released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Development

No branches or pull requests

3 participants