forked from docker/libcompose
/
labels.go
46 lines (35 loc) · 854 Bytes
/
labels.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
package docker
import (
"encoding/json"
"github.com/docker/libcompose/utils"
)
type Label string
const (
NAME = Label("io.docker.compose.name")
PROJECT = Label("io.docker.compose.project")
SERVICE = Label("io.docker.compose.service")
HASH = Label("io.docker.compose.config-hash")
)
func (f Label) Eq(value string) string {
return utils.LabelFilter(string(f), value)
}
func And(left, right string) string {
leftMap := map[string][]string{}
rightMap := map[string][]string{}
// Ignore errors
json.Unmarshal([]byte(left), &leftMap)
json.Unmarshal([]byte(right), &rightMap)
for k, v := range rightMap {
existing, ok := leftMap[k]
if ok {
leftMap[k] = append(existing, v...)
} else {
leftMap[k] = v
}
}
result, _ := json.Marshal(leftMap)
return string(result)
}
func (f Label) Str() string {
return string(f)
}