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

Is func (*Validate) Struct thread-safe ? #315

Closed
7fELF opened this issue Oct 12, 2017 · 4 comments
Closed

Is func (*Validate) Struct thread-safe ? #315

7fELF opened this issue Oct 12, 2017 · 4 comments

Comments

@7fELF
Copy link

7fELF commented Oct 12, 2017

Package version:

v9

Issue, Question or Enhancement:

Question

I'm using func (*Validate) Struct to validate API requests.
Is that safe to use only one instance of Validate for the whole project considering there may be simultaneous calls to (*Validate) Struct()?

@deankarn
Copy link
Contributor

Hey @7fELF great question

And the answer is yes it is completely thread/goroutine safe and is designed to be used with a single instance. Validator also caches information about your struct and validations, in essence only parsing your validation tags once per struct type, without a single instance you wouldn’t get the advantages of the cache.

@7fELF
Copy link
Author

7fELF commented Oct 12, 2017

Thanks for the quick answer 😄

@7fELF 7fELF closed this as completed Oct 12, 2017
@andrascz
Copy link
Contributor

Hey @7fELF great question

And the answer is yes it is completely thread/goroutine safe and is designed to be used with a single instance. Validator also caches information about your struct and validations, in essence only parsing your validation tags once per struct type, without a single instance you wouldn’t get the advantages of the cache.

Could be this represented somewhere in the documentation? There are some functions noted as not thread-safe which is not really an assurance that the other functions are thread-safe.

@deankarn
Copy link
Contributor

PRs welcome @andrascz

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

No branches or pull requests

3 participants