forked from traefik/traefik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
label.go
34 lines (28 loc) · 1.13 KB
/
label.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
// Package label implements the decoding and encoding between flat labels and a typed Configuration.
package label
import (
"github.com/cgws/traefik/v2/pkg/config/dynamic"
"github.com/cgws/traefik/v2/pkg/config/parser"
)
// DecodeConfiguration converts the labels to a configuration.
func DecodeConfiguration(labels map[string]string) (*dynamic.Configuration, error) {
conf := &dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{},
TCP: &dynamic.TCPConfiguration{},
UDP: &dynamic.UDPConfiguration{},
}
err := parser.Decode(labels, conf, parser.DefaultRootName, "traefik.http", "traefik.tcp", "traefik.udp")
if err != nil {
return nil, err
}
return conf, nil
}
// EncodeConfiguration converts a configuration to labels.
func EncodeConfiguration(conf *dynamic.Configuration) (map[string]string, error) {
return parser.Encode(conf, parser.DefaultRootName)
}
// Decode converts the labels to an element.
// labels -> [ node -> node + metadata (type) ] -> element (node)
func Decode(labels map[string]string, element interface{}, filters ...string) error {
return parser.Decode(labels, element, parser.DefaultRootName, filters...)
}