Skip to content

Commit

Permalink
fix: JSON use JSON parser
Browse files Browse the repository at this point in the history
Signed-off-by: rogerogers <rogers@rogerogers.com>
  • Loading branch information
rogerogers committed Jun 11, 2024
1 parent 53029a9 commit 66d4e43
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions consul/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
package consul

import (
"encoding/json"
"fmt"
"time"

"sigs.k8s.io/yaml/goyaml.v3"
yaml "sigs.k8s.io/yaml/goyaml.v3"
)

type ConfigType string
Expand Down Expand Up @@ -53,8 +54,9 @@ type parser struct{}

func (p *parser) Decode(configType ConfigType, data string, config interface{}) error {
switch configType {
case JSON, YAML:
// since YAML is a superset of JSON, it can parse JSON using a YAML parser
case JSON:
return json.Unmarshal([]byte(data), config)
case YAML:
return yaml.Unmarshal([]byte(data), config)
default:
return fmt.Errorf("unsupported config data type %s", configType)
Expand Down

0 comments on commit 66d4e43

Please sign in to comment.