Aded test coverage for form submissions. Added validator as a service.

This commit is contained in:
mikestefanello 2021-12-25 00:11:59 -05:00
parent cc2f25431b
commit 6501621136
8 changed files with 111 additions and 30 deletions

26
services/validator.go Normal file
View file

@ -0,0 +1,26 @@
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
func (v *Validator) Validate(i interface{}) error {
if err := v.validator.Struct(i); err != nil {
return err
}
return nil
}