Skip to content

Commit

Permalink
fix: return empty iterator if no json present
Browse files Browse the repository at this point in the history
  • Loading branch information
uubulb committed Jan 16, 2025
1 parent 1d8583c commit 2df72c2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/utils/gjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ var (
ErrGjsonWrongType = errors.New("wrong type")
)

var emptyIterator = func(yield func(string, string) bool) {}

func GjsonGet(json []byte, path string) (gjson.Result, error) {
result := gjson.GetBytes(json, path)
if !result.Exists() {
Expand All @@ -23,7 +25,7 @@ func GjsonGet(json []byte, path string) (gjson.Result, error) {

func GjsonIter(json string) (iter.Seq2[string, string], error) {
if json == "" {
return nil, nil
return emptyIterator, nil
}

result := gjson.Parse(json)
Expand Down

0 comments on commit 2df72c2

Please sign in to comment.