Skip to content

Commit

Permalink
Merge pull request #5 from rogerogers/fix/json
Browse files Browse the repository at this point in the history
fix: JSON use JSON parser
  • Loading branch information
rogerogers committed Jun 11, 2024
2 parents 53029a9 + 66d4e43 commit 635207e
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 635207e

Please sign in to comment.