mirror of
https://github.com/KevinMidboe/traefik-etcd-advertiser.git
synced 2025-10-29 18:00:19 +00:00
init
This commit is contained in:
18
converter/json.go
Normal file
18
converter/json.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package converter
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
|
||||
"github.com/traefik/traefik/v3/pkg/config/dynamic"
|
||||
)
|
||||
|
||||
func TraefikToJSON(config *dynamic.Configuration) map[string]interface{} {
|
||||
var data map[string]interface{}
|
||||
jsonData, _ := json.Marshal(config)
|
||||
if err := json.Unmarshal(jsonData, &data); err != nil {
|
||||
log.Printf("failed to unmarshal JSON: %w", err)
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
28
converter/yaml.go
Normal file
28
converter/yaml.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package converter
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/traefik/traefik/v3/pkg/config/dynamic"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func TraefikFromYaml(filePath string) (*dynamic.Configuration, error) {
|
||||
file, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
var cfg dynamic.Configuration
|
||||
decoder := yaml.NewDecoder(file)
|
||||
if err := decoder.Decode(&cfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
func TraefikToYaml(config *dynamic.Configuration) string {
|
||||
return ""
|
||||
}
|
||||
Reference in New Issue
Block a user