mirror of https://github.com/go-gorm/gorm.git
reduce DB's Use method complexity and make it easier to understand (#3930)
This commit is contained in:
parent
d888c799d7
commit
f9131e309d
13
gorm.go
13
gorm.go
|
@ -380,15 +380,14 @@ func (db *DB) SetupJoinTable(model interface{}, field string, joinTable interfac
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) Use(plugin Plugin) (err error) {
|
func (db *DB) Use(plugin Plugin) error {
|
||||||
name := plugin.Name()
|
name := plugin.Name()
|
||||||
if _, ok := db.Plugins[name]; !ok {
|
if _, ok := db.Plugins[name]; ok {
|
||||||
if err = plugin.Initialize(db); err == nil {
|
|
||||||
db.Plugins[name] = plugin
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return ErrRegistered
|
return ErrRegistered
|
||||||
}
|
}
|
||||||
|
if err := plugin.Initialize(db); err != nil {
|
||||||
return err
|
return err
|
||||||
|
}
|
||||||
|
db.Plugins[name] = plugin
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue