2019-06-17 09:48:05 +00:00
|
|
|
// Package label implements the decoding and encoding between flat labels and a typed Configuration.
|
|
|
|
package label
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/containous/traefik/pkg/config"
|
|
|
|
"github.com/containous/traefik/pkg/config/parser"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DecodeConfiguration converts the labels to a configuration.
|
|
|
|
func DecodeConfiguration(labels map[string]string) (*config.Configuration, error) {
|
|
|
|
conf := &config.Configuration{
|
|
|
|
HTTP: &config.HTTPConfiguration{},
|
|
|
|
TCP: &config.TCPConfiguration{},
|
|
|
|
}
|
|
|
|
|
2019-06-21 08:08:04 +00:00
|
|
|
err := parser.Decode(labels, conf, parser.DefaultRootName, "traefik.http", "traefik.tcp")
|
2019-06-17 09:48:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// EncodeConfiguration converts a configuration to labels.
|
|
|
|
func EncodeConfiguration(conf *config.Configuration) (map[string]string, error) {
|
2019-06-21 08:08:04 +00:00
|
|
|
return parser.Encode(conf, parser.DefaultRootName)
|
2019-06-17 09:48:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
2019-06-21 08:08:04 +00:00
|
|
|
return parser.Decode(labels, element, parser.DefaultRootName, filters...)
|
2019-06-17 09:48:05 +00:00
|
|
|
}
|