From 66d4e4322290f93ae33b8e2659857f4bf96d749c Mon Sep 17 00:00:00 2001 From: rogerogers Date: Tue, 11 Jun 2024 10:42:45 +0800 Subject: [PATCH] fix: JSON use JSON parser Signed-off-by: rogerogers --- consul/parser.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/consul/parser.go b/consul/parser.go index 3dde075..8cd20b0 100644 --- a/consul/parser.go +++ b/consul/parser.go @@ -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 @@ -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)