second commit
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package validator
|
||||
|
||||
import (
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
// Validate holds the validator instance
|
||||
var validate *validator.Validate
|
||||
|
||||
// Init initializes the global validator
|
||||
func Init() {
|
||||
validate = validator.New()
|
||||
}
|
||||
|
||||
// ValidateStruct validates a struct using go-playground/validator tags
|
||||
func ValidateStruct(s interface{}) error {
|
||||
if validate == nil {
|
||||
Init()
|
||||
}
|
||||
return validate.Struct(s)
|
||||
}
|
||||
|
||||
// Var validates a single variable
|
||||
func Var(field interface{}, tag string) error {
|
||||
if validate == nil {
|
||||
Init()
|
||||
}
|
||||
return validate.Var(field, tag)
|
||||
}
|
||||
Reference in New Issue
Block a user