Search code examples
gogo-gorm

Is there a simple way to validate data with gorm?


I'm new to GORM and I was looking for something that would help handle frequent validation errors (field length, regexp|email, uniqueness and so on) that I could use on the struct fields.

For now I just found blog posts explaining to use the beforeSave() method, but that would mean to manually check every field one by one.

I also found the qor/validations lib that would suit my needs, but it seems abandoned.

Are there other ways to do it ?


Solution

  • I totally forgot about go-playground/validator, which can validate any struct (So it can be applied to a struct representing a GORM entity as well).