mirror of https://github.com/go-gorm/gorm.git
Cheanged if to switch in scope.go
Readability improved by changing a long if-else to a switch statement.
This commit is contained in:
parent
375f3ee260
commit
41eeeeea7c
23
scope.go
23
scope.go
|
@ -174,21 +174,14 @@ func (scope *Scope) CallMethod(name string) {
|
||||||
|
|
||||||
call := func(value interface{}) {
|
call := func(value interface{}) {
|
||||||
if fm := reflect.ValueOf(value).MethodByName(name); fm.IsValid() {
|
if fm := reflect.ValueOf(value).MethodByName(name); fm.IsValid() {
|
||||||
fi := fm.Interface()
|
switch f := fm.Interface().(type) {
|
||||||
if f, ok := fi.(func()); ok {
|
case func(): f()
|
||||||
f()
|
case func(s *Scope): f(scope)
|
||||||
} else if f, ok := fi.(func(s *Scope)); ok {
|
case func(s *DB): f(scope.db.new())
|
||||||
f(scope)
|
case func() error: scope.Err(f())
|
||||||
} else if f, ok := fi.(func(s *DB)); ok {
|
case func(s *Scope) error: scope.Err(f(scope))
|
||||||
f(scope.db.new())
|
case func(s *DB) error: scope.Err(f(scope.db.new()))
|
||||||
} else if f, ok := fi.(func() error); ok {
|
default: scope.Err(errors.New(fmt.Sprintf("unsupported function %v", name)))
|
||||||
scope.Err(f())
|
|
||||||
} else if f, ok := fi.(func(s *Scope) error); ok {
|
|
||||||
scope.Err(f(scope))
|
|
||||||
} else if f, ok := fi.(func(s *DB) error); ok {
|
|
||||||
scope.Err(f(scope.db.new()))
|
|
||||||
} else {
|
|
||||||
scope.Err(errors.New(fmt.Sprintf("unsupported function %v", name)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue