Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: JSON use JSON parser #5

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading