mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-22 12:48:14 -05:00
fix: return empty iterator if no json present
This commit is contained in:
parent
1d8583ca8c
commit
2df72c2e49
@ -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() {
|
||||
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user