Categorygithub.com/zoncoen/query-go
modulepackage
1.3.2
Repository: https://github.com/zoncoen/query-go.git
Documentation: pkg.go.dev

# README

query-go

GoDoc coverage ratio Go Report Card LICENSE

This is a Go package to extract element from a Go value by a query string like $.key[0].key['key']. See usage and example in GoDoc.

Basic Usage

ParseString parses a query string and returns the query which extracts the value.

q, err := query.ParseString(`$.key[0].key['key']`)
v, err := q.Extract(target)

Query Syntax

The query syntax understood by this package when parsing is as follows.

$           the root element
.key        extracts by a key of map or field name of struct ("." can be omitted if the head of query)
['key']     same as the ".key" (if the key contains "\" or "'", these characters must be escaped like "\\", "\'")
[0]         extracts by a index of array or slice

# Packages

Package ast declares the types used to represent syntax trees.
Package parser implements a parser for a query string.
Package token defines constants representing the lexical tokens.

# Functions

CaseInsensitive returns the Option to match case insensitivity.
CustomExtractFunc returns the Option to customize the behavior of extractors.
CustomIsInlineStructFieldFunc returns the Option to customize the behavior of extractors.
CustomStructFieldNameGetter returns the Option to set f as custom function which gets struct field name.
ExtractByStructTag returns the Option to allow extracting by struct tag.
IsCaseInsensitive reports whether case-insensitive querying is enabled or not.
New returns a new query.
Parse parses a query string via r and returns the corresponding Query.
ParseString parses a query string s and returns the corresponding Query.

# Structs

Index represents an extractor to access the value by index.
Key represents an extractor to access the value by key.
Query represents a query to extract the element from a value.

# Interfaces

An Extractor interface is used by a query to extract the element from a value.
IndexExtractor is the interface that wraps the ExtractByIndex method.
KeyExtractor is the interface that wraps the ExtractByKey method.
KeyExtractorContext is the interface that wraps the ExtractByKey method.

# Type aliases

ExtractFunc represents a function to extracts a value.
Option represents an option for Query.