commonpath

package
v1.21.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package commonpath contains functions used for path.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindValues

func FindValues(doc *types.Document, path types.Path, opts *FindValuesOpts) ([]any, error)

FindValues returns values by path, looking up into arrays.

It iterates path elements, at each path element it adds to next values to iterate:

  • if it is a document and has path, it adds the document field value to next values;
  • if it is an array, FindArrayIndex is true and finds value at index, it adds value to next values;
  • if it is an array, FindArrayDocuments is true and documents in the array have path, it adds field value of all documents that have path to next values.

It returns next values after iterating path elements.

Types

type FindValuesOpts

type FindValuesOpts struct {
	// If FindArrayDocuments is true, it iterates the array to find documents that have path.
	// If FindArrayDocuments is false, it does not find documents from the array.
	// Using path `v.foo` and `v` is an array:
	//  - with FindArrayDocuments true, it finds values of `foo` of found documents;
	//  - with FindArrayDocuments false, it returns an empty array.
	// If `v` is not an array, FindArrayDocuments has no impact.
	FindArrayDocuments bool
	// If FindArrayIndex is true, it finds value at index of an array.
	// If FindArrayIndex is false, it does not find value at index of an array.
	// Using path `v.0` and `v` is an array:
	//  - with FindArrayIndex true, it finds 0-th index value of the array;
	//  - with FindArrayIndex false, it returns empty array.
	// If `v` is not an array, FindArrayIndex has no impact.
	FindArrayIndex bool
}

FindValuesOpts sets options for FindValues.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL