2021-12-24 21:11:59 -08:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/go-playground/validator/v10"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Validator provides validation mainly validating structs within the web context
|
|
|
|
type Validator struct {
|
|
|
|
// validator stores the underlying validator
|
|
|
|
validator *validator.Validate
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewValidator creats a new Validator
|
|
|
|
func NewValidator() *Validator {
|
|
|
|
return &Validator{
|
|
|
|
validator: validator.New(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate validates a struct
|
2023-12-16 08:07:20 -08:00
|
|
|
func (v *Validator) Validate(i any) error {
|
2021-12-24 21:11:59 -08:00
|
|
|
if err := v.validator.Struct(i); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|