func (obsc *ObjectScraper) extractFirstValue(data []byte, path *jsonpath.Path) (*jsonpath.Result, error) { eval, err := jsonpath.EvalPathsInBytes(data, []*jsonpath.Path{path}) if err != nil { return nil, fmt.Errorf("failed to eval jsonpath;err:<%s>", err) } result, ok := eval.Next() if !ok { return nil, fmt.Errorf("no value found for path") } return result, nil }
func (vs *ValueScraper) forTargetValue(data []byte, handle func(*jsonpath.Result)) error { eval, err := jsonpath.EvalPathsInBytes(data, []*jsonpath.Path{vs.valueJsonPath}) if err != nil { return fmt.Errorf("failed to eval jsonpath;path:<%s>,json:<%s>", vs.valueJsonPath, data) } for { result, ok := eval.Next() if !ok { break } handle(result) } return nil }