2017-05-20 14:46:29 +02:00
|
|
|
package all
|
|
|
|
|
2018-01-07 21:00:56 +01:00
|
|
|
import (
|
|
|
|
"github.com/FreifunkBremen/yanic/runtime"
|
|
|
|
)
|
2017-05-20 14:46:29 +02:00
|
|
|
|
|
|
|
// 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 {
|
2018-01-07 21:00:56 +01:00
|
|
|
nodes := runtime.NewNodes(&runtime.NodesConfig{})
|
2017-05-20 14:46:29 +02:00
|
|
|
filterfuncs := []filterFunc{
|
|
|
|
f.HasLocation(),
|
|
|
|
f.Blacklist(),
|
|
|
|
f.InArea(),
|
|
|
|
f.NoOwner(),
|
|
|
|
}
|
|
|
|
|
2017-11-22 12:58:29 +01:00
|
|
|
nodesOrigin.Lock()
|
|
|
|
defer nodesOrigin.Unlock()
|
|
|
|
|
2017-05-20 14:46:29 +02:00
|
|
|
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
|
|
|
|
}
|