Looking at this callback (line 412), is it possible to break out of the callback loop from inside the callback function itself? Or would I need to wrap it or extend it in some way to create that capability?
This is the code:
jsonparser.ArrayEach(data, func(value []byte, dataType jsonparser.ValueType, offset int, err error) {
if v, err := jsonparser.GetUnsafeString(value, "username"); nil == err && v == lookFor {
z = v
return // Abort in some way?
}
})
The library is still waiting for a query-like update so for now this is the cheapest way to find a value, which still outperforms any full json
parser by far (doing about 9.21x to 9.38x faster on benchmarks). So I'm kind of aiming for a LIMIT 1
-ish solution.
I was thinking of doing a full copy-paste and making an cloned version on the interface and making..
if t != NotExist {
cb(v, t, o, e)
}
into...
if t != NotExist {
boolVal = cb(v, t, o, e) // Extending it to have a return value
}
... return a boolean
and validate as a continue indicator. But would there be a more clean way without fully duplicating this code?