jsonmatcher

package
v0.0.0-...-f696b34 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EncounteredStats

type EncounteredStats struct {
	TimesSeen    atomic.Int64 `json:"times_seen"`
	TimesMatched atomic.Int64 `json:"times_matched"`
	Examples     *ExampleList `json:"examples,omitempty"`
}

type ExampleList

type ExampleList struct {
	// contains filtered or unexported fields
}

func (*ExampleList) Get

func (el *ExampleList) Get() []string

type FieldStats

type FieldStats struct {
	Expecting       []expectedType                        `json:"expecting"`
	TimesSampled    atomic.Int64                          `json:"times_sampled"`
	TypesEnountered [numEncounteredTypes]EncounteredStats `json:"types_encountered"`
}

TODO: Replace uber types with native types pending MarshalScalar (see field_stats.go)

func NewFieldStats

func NewFieldStats(expectedTypes ...expectedType) *FieldStats

func (*FieldStats) MarshalJson

func (n *FieldStats) MarshalJson() ([]byte, error)

type MatchStats

type MatchStats struct {
	NodeName     string        `json:"node_name"`
	TimesChecked int64         `json:"times_checked"`
	TimesMatched int64         `json:"times_matched"`
	Children     []*MatchStats `json:"children,omitempty"`
}

type Matcher

type Matcher struct {
	// contains filtered or unexported fields
}

Matcher performs an AQL query against JSON to see if it matches

Example
const json = `{
		"date": "1970-01-02",
		"number": 2,
		"name": "Andy",
		"description": "大懒虫"
	}`

m, err := NewMatcher(`name:"andy" AND date:><(1970-01-01,1980-01-01)`)
if err != nil {
	log.Fatalf("error running query: %v", err)
}

result, err := m.Match([]byte(json))
if err != nil {
	log.Fatalf("error during match: %v", err)
}
fmt.Println(result)
Output:

true

func NewMatcher

func NewMatcher(aqlQuery string) (*Matcher, error)

NewMatcher creates a new matcher that returns whether a JSON document matches an AQL query

func (*Matcher) Match

func (m *Matcher) Match(data []byte) (bool, error)

Match returns whether or not the query matches on a JSON document.

func (*Matcher) Messages

func (m *Matcher) Messages() []*parser.ParserMessage

Messages will return any hints or warning messages that the matcher may have generated during parsing

func (*Matcher) Query

func (m *Matcher) Query() string

Query will return the query string the matcher was created with

func (*Matcher) Stats

func (m *Matcher) Stats() *MatchStats

type MatcherOption

type MatcherOption func(*Matcher) error

func TrackQueryStats

func TrackQueryStats() MatcherOption

type Val

type Val interface {
	Type() ValueType
	Bool() (bool, bool)
	String() (string, bool)
	Float() (float64, bool)
	Int() (int, bool)
	Date() (time.Time, bool)
}

type ValueType

type ValueType int
const (
	Bool ValueType
	Float
	Int
	String
	Date
	Null
)

type VelueProvider

type VelueProvider interface {
	Get(path []string) (values []Val, found bool)
}

TODO: research implementing Impl [JSON]ValueProvider

Jump to

Keyboard shortcuts

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