package mgocrud import ( validator "gopkg.in/go-playground/validator.v8" "gopkg.in/mgo.v2/bson" ) // ValidateObject validates object via validator tag and custom method func (db *MgoDatabase) ValidateObject(m ModelInterface, changes bson.M) error { // first validate via struct tag validator := validator.New(&validator.Config{ TagName: "validator", }) err := validator.Struct(m) if err != nil { return err } // next execute custom model validator if exists if i, ok := m.(interface { Validate(db Database, changes bson.M) error }); ok { return i.Validate(db, changes) } return nil }