-
Notifications
You must be signed in to change notification settings - Fork 0
/
by.go
89 lines (69 loc) · 1.82 KB
/
by.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package service // import "github.com/docker/docker/volume/service"
import (
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/volume"
)
// By is an interface which is used to implement filtering on volumes.
type By interface {
isBy()
}
// ByDriver is `By` that filters based on the driver names that are passed in
func ByDriver(drivers ...string) By {
return byDriver(drivers)
}
type byDriver []string
func (byDriver) isBy() {}
// ByReferenced is a `By` that filters based on if the volume has references
type ByReferenced bool
func (ByReferenced) isBy() {}
// And creates a `By` combining all the passed in bys using AND logic.
func And(bys ...By) By {
and := make(andCombinator, 0, len(bys))
for _, by := range bys {
and = append(and, by)
}
return and
}
type andCombinator []By
func (andCombinator) isBy() {}
// Or creates a `By` combining all the passed in bys using OR logic.
func Or(bys ...By) By {
or := make(orCombinator, 0, len(bys))
for _, by := range bys {
or = append(or, by)
}
return or
}
type orCombinator []By
func (orCombinator) isBy() {}
// CustomFilter is a `By` that is used by callers to provide custom filtering
// logic.
type CustomFilter filterFunc
func (CustomFilter) isBy() {}
// FromList returns a By which sets the initial list of volumes to use
func FromList(ls *[]volume.Volume, by By) By {
return &fromList{by: by, ls: ls}
}
type fromList struct {
by By
ls *[]volume.Volume
}
func (fromList) isBy() {}
func byLabelFilter(filter filters.Args) By {
return CustomFilter(func(v volume.Volume) bool {
dv, ok := v.(volume.DetailedVolume)
if !ok {
return false
}
labels := dv.Labels()
if !filter.MatchKVList("label", labels) {
return false
}
if filter.Contains("label!") {
if filter.MatchKVList("label!", labels) {
return false
}
}
return true
})
}