Labels parser.

This commit is contained in:
Ludovic Fernandez 2018-12-04 14:24:04 +01:00 committed by Traefiker Bot
parent 92f8e5cd3f
commit 11a0078966
16 changed files with 4462 additions and 4 deletions

39
provider/label/parser.go Normal file
View file

@ -0,0 +1,39 @@
package label
import (
"github.com/containous/traefik/config"
"github.com/containous/traefik/provider/label/internal"
)
// Decode Converts the labels to a configuration.
// labels -> [ node -> node + metadata (type) ] -> element (node)
func Decode(labels map[string]string) (*config.Configuration, error) {
node, err := internal.DecodeToNode(labels)
if err != nil {
return nil, err
}
conf := &config.Configuration{}
err = internal.AddMetadata(conf, node)
if err != nil {
return nil, err
}
err = internal.Fill(conf, node)
if err != nil {
return nil, err
}
return conf, nil
}
// Encode Converts a configuration to labels.
// element -> node (value) -> label (node)
func Encode(conf *config.Configuration) (map[string]string, error) {
node, err := internal.EncodeToNode(conf)
if err != nil {
return nil, err
}
return internal.EncodeNode(node), nil
}