mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-22 20:58: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")
|
ErrGjsonWrongType = errors.New("wrong type")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var emptyIterator = func(yield func(string, string) bool) {}
|
||||||
|
|
||||||
func GjsonGet(json []byte, path string) (gjson.Result, error) {
|
func GjsonGet(json []byte, path string) (gjson.Result, error) {
|
||||||
result := gjson.GetBytes(json, path)
|
result := gjson.GetBytes(json, path)
|
||||||
if !result.Exists() {
|
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) {
|
func GjsonIter(json string) (iter.Seq2[string, string], error) {
|
||||||
if json == "" {
|
if json == "" {
|
||||||
return nil, nil
|
return emptyIterator, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
result := gjson.Parse(json)
|
result := gjson.Parse(json)
|
||||||
|
Loading…
Reference in New Issue
Block a user