mirror of
https://github.com/navidrome/navidrome.git
synced 2026-05-03 06:51:16 +00:00
Replaced the Fields() type switch with a fields() method on the Expression interface, eliminating the need to update a central switch when adding new expression types. Removed the now-redundant criteriaExpression() marker method since fields() alone suffices to restrict the interface. Extracted a conjunction interface for the ChildPlaylistIds() lookup used by All and Any.
38 lines
776 B
Go
38 lines
776 B
Go
package criteria
|
|
|
|
import "fmt"
|
|
|
|
type Visitor func(Expression) error
|
|
|
|
func Walk(expr Expression, visit Visitor) error {
|
|
if expr == nil {
|
|
return nil
|
|
}
|
|
if err := visit(expr); err != nil {
|
|
return err
|
|
}
|
|
switch e := expr.(type) {
|
|
case All:
|
|
for _, child := range e {
|
|
if err := Walk(child, visit); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
case Any:
|
|
for _, child := range e {
|
|
if err := Walk(child, visit); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
case Is, IsNot, Gt, Lt, Before, After, Contains, NotContains, StartsWith, EndsWith, InTheRange, InTheLast, NotInTheLast, InPlaylist, NotInPlaylist:
|
|
return nil
|
|
default:
|
|
return fmt.Errorf("unknown criteria expression type %T", expr)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func Fields(expr Expression) map[string]any {
|
|
return expr.fields()
|
|
}
|