yanic/output/all/filter.go

44 lines
809 B
Go
Raw Normal View History

package all
import "github.com/FreifunkBremen/yanic/runtime"
// Config Filter
type filterConfig map[string]interface{}
type filterFunc func(*runtime.Node) *runtime.Node
func noFilter(node *runtime.Node) *runtime.Node {
return node
}
// Create Filter
func (f filterConfig) filtering(nodesOrigin *runtime.Nodes) *runtime.Nodes {
nodes := runtime.NewNodes(&runtime.Config{})
filterfuncs := []filterFunc{
f.HasLocation(),
f.Blacklist(),
f.InArea(),
2018-01-04 14:45:04 +01:00
f.Sites(),
f.NoOwner(),
}
2017-11-22 12:58:29 +01:00
nodesOrigin.Lock()
defer nodesOrigin.Unlock()
for _, nodeOrigin := range nodesOrigin.List {
//maybe cloning of this object is better?
node := nodeOrigin
for _, f := range filterfuncs {
node = f(node)
if node == nil {
break
}
}
if node != nil {
nodes.AddNode(node)
}
}
return nodes
}