Validator: Is `func (*Validate) Struct` thread-safe ?

Created on 12 Oct 2017  路  2Comments  路  Source: go-playground/validator

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()?

Most helpful comment

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鈥檛 get the advantages of the cache.

All 2 comments

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鈥檛 get the advantages of the cache.

Thanks for the quick answer :smile:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

phenrigomes picture phenrigomes  路  5Comments

romangithub1024 picture romangithub1024  路  5Comments

dkostenko picture dkostenko  路  5Comments

alexyans picture alexyans  路  3Comments

AlexMain picture AlexMain  路  3Comments