Skip to content

Commit

Permalink
readability: more if depths, but show exclusive blocks explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
sio4 committed Jan 13, 2023
1 parent e2fe45b commit 1082c83
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ type AfterEagerFindable interface {
}

func (m *Model) afterFind(c *Connection, eager bool) error {
if x, ok := m.Value.(AfterFindable); ok && !eager {
if err := x.AfterFind(c); err != nil {
return err
if eager {
if x, ok := m.Value.(AfterEagerFindable); ok {
if err := x.AfterEagerFind(c); err != nil {
return err
}
}
}
if x, ok := m.Value.(AfterEagerFindable); ok && eager {
if err := x.AfterEagerFind(c); err != nil {
return err
} else {
if x, ok := m.Value.(AfterFindable); ok {
if err := x.AfterFind(c); err != nil {
return err
}
}
}

Expand All @@ -46,13 +49,17 @@ func (m *Model) afterFind(c *Connection, eager bool) error {
wg.Go(func() error {
y := rv.Index(i)
y = y.Addr()
if x, ok := y.Interface().(AfterFindable); ok && !eager {
return x.AfterFind(c)
}

if x, ok := y.Interface().(AfterEagerFindable); ok && eager {
return x.AfterEagerFind(c)
if eager {
if x, ok := y.Interface().(AfterEagerFindable); ok {
return x.AfterEagerFind(c)
}
} else {
if x, ok := y.Interface().(AfterFindable); ok {
return x.AfterFind(c)
}
}

return nil
})
}(i)
Expand Down

0 comments on commit 1082c83

Please sign in to comment.