2017-05-20 14:46:29 +02:00
|
|
|
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(),
|
2017-05-20 14:46:29 +02:00
|
|
|
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
|
|
|
|
}
|