30 lines
565 B
Go
30 lines
565 B
Go
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)
|
|
}
|