pathing

package
v0.0.0-...-3122f37 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package pathing is a collection of functions that are able to extract values from data using on a path/query.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Checks

func Checks(ex Extractor, pcs PathChecks) check.Func

Checks extracts paths (keys of the given PathChecks and passes the value add that path to a check.Func for assertion.

func GJSON

func GJSON(source, path string) (found []string, err error)

GJSON (https://github.com/tidwall/gjson) for JSON extraction. This is a valid Extractor that can be used for JSON in place of JSON if desired. This function has two special cases where it does not behave the same as GJSON, if the path is and empty string when source is not then source is returned as is in a slice, the second case is when value extracted is a map/hash then it will skip iterating over keys and return the full json of the map for optional nesting of Checks. Produces an error when no value is extracted.

func GJSONChecks

func GJSONChecks(pcs PathChecks) check.Func

GJSONChecks is a preloaded version of Checks with GJSON as the extractor.

func JSON

func JSON(source, path string) (found []string, err error)

JSON meets the Extractor type for extracting JSON data with JSONPath. This extractor uses http://github.com/Nekroze/jsonpath which describes the supported jsonpath expressions/paths/addresses that you may use. Produces an error when a value cannot be extract for non wildcard paths.

func JSONChecks

func JSONChecks(pcs PathChecks) check.Func

JSONChecks is a preloaded version of Checks with JSON as an extractor.

func RegexpChecks

func RegexpChecks(expression string, pcs PathChecks) check.Func

Types

type Extractor

type Extractor func(source, path string) ([]string, error)

An Extractor is any func that takes two strings and returns a slice of strings and an error. These functions take a source string and a path string. The source string is the structured text document that this extractor will try to extract data from. The path string is an address/expression in a pathing DSL (eg. XPath or JSonPath) that describes what data should be extracted from the source. All Extractors should return the extracted data as a slice of string along with an error to indicate failure or success.

type PathChecks

type PathChecks map[string]check.Func

PathChecks is a collection of path expressions for a given Extrator and check.Func's to check the value(s) with.

type RegexpExtractor

type RegexpExtractor struct {
	Expression *regexp.Regexp
}

func NewRegexpExtractor

func NewRegexpExtractor(expression string) RegexpExtractor

func (RegexpExtractor) Extractor

func (rc RegexpExtractor) Extractor(source, captureGroup string) (found []string, err error)

Jump to

Keyboard shortcuts

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