Skip to content

Commit 3daacc1

Browse files
committed
fix: use yaml.v3 instead of yaml.v2
- yaml.v2 has a bug where the sub-maps are converted to `map[interface]interface{}` instead of `map[string]interface{}` Signed-off-by: Suraj Banakar <surajrbanakar@gmail.com>
1 parent bee2c98 commit 3daacc1

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

pkg/sync/filepath_sync.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ package sync
22

33
import (
44
"context"
5+
"encoding/json"
56
"errors"
67
"fmt"
78
"os"
89

9-
jsoniter "github.com/json-iterator/go"
10-
"gopkg.in/yaml.v2"
10+
"gopkg.in/yaml.v3"
1111

1212
"github.com/fsnotify/fsnotify"
1313
"github.com/open-feature/flagd/pkg/logger"
@@ -39,7 +39,7 @@ func (fs *FilePathSync) Fetch(_ context.Context) (string, error) {
3939
case "yaml":
4040
fallthrough
4141
case "yml":
42-
return yamlToJson(rawFile)
42+
return yamlToJSON(rawFile)
4343
case "json":
4444
return string(rawFile), nil
4545
default:
@@ -116,15 +116,9 @@ func yamlToJSON(rawFile []byte) (string, error) {
116116
return "", fmt.Errorf("unmarshal yaml: %w", err)
117117
}
118118

119-
// json.Marshal can marshal map[string]interface{} to []byte
120-
// but it can't marshal map[interface]interface{} to []byte
121-
// We are using jsoniter library here because jsoniter.Marhsal
122-
// can convert map[interface]interface{} to []byte
123-
// More info:https://stackoverflow.com/q/35377477/6874596
124-
var jsonit = jsoniter.ConfigCompatibleWithStandardLibrary
125119
// Adding spaces here because our evaluator transposer function
126120
// doesn't understand json without indentations quite well
127-
r, err := jsonit.MarshalIndent(ms, "", " ")
121+
r, err := json.MarshalIndent(ms, "", " ")
128122
if err != nil {
129123
return "", fmt.Errorf("convert yaml to json: %w", err)
130124
}

0 commit comments

Comments
 (0)