querystring

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

README

go-querystring-parser

A golang Elasticsearch Querystring parser

Usage

import (
    querystring "https://github.com/Group-IB/go-querystring-parser"
)

Then use:

query := "message: test\\ value AND datetime: [\"2020-01-01T00:00:00\" TO \"2020-12-31T00:00:00\"]"
ast, err := querystring.Parse(query)
if err != nil {
    // error handling
}

// do something with ast

The AST parsed from above querystring:

// print via github.com/davecgh/go-spew.Dump
(*querystring.AndCondition)(0xc00000c200)({
    Left: (*querystring.MatchCondition)(0xc00000c1e0)({
        Field: (string) (len=7) "message",
        Value: (string) (len=10) "test value"
    }),
    Right: (*querystring.TimeRangeCondition)(0xc000076750)({
        Field: (string) (len=8) "datetime",
        Start: (*string)(0xc0000545b0)((len=19) "2020-01-01T00:00:00"),
        End: (*string)(0xc0000545c0)((len=19) "2020-12-31T00:00:00"),
        IncludeStart: (bool) true,
        IncludeEnd: (bool) true
    })
})

For Developers

After edit querystring.y, gen code via run:

go generate

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AndCondition

type AndCondition struct {
	Left  Condition
	Right Condition
}

AndCondition .

func NewAndCondition

func NewAndCondition(left, right Condition) *AndCondition

NewAndCondition .

type Condition

type Condition interface {
}

Condition .

func Parse

func Parse(query string) (rq Condition, err error)

Parse querystring and return Condition

type FieldableCondition

type FieldableCondition interface {
	GetField() string
	SetField(field string)
}

FieldableCondition .

type MatchCondition

type MatchCondition struct {
	Field string
	Value string
}

MatchCondition .

func NewMatchCondition

func NewMatchCondition(s string) *MatchCondition

NewMatchCondition .

func (*MatchCondition) GetField

func (q *MatchCondition) GetField() string

GetField .

func (*MatchCondition) SetField

func (q *MatchCondition) SetField(field string)

SetField .

type NotCondition

type NotCondition struct {
	Condition Condition
}

NotCondition .

func NewNotCondition

func NewNotCondition(q Condition) *NotCondition

NewNotCondition .

type NumberRangeCondition

type NumberRangeCondition struct {
	Field        string
	Start        *int64
	End          *int64
	IncludeStart bool
	IncludeEnd   bool
}

NumberRangeCondition .

func MustNewNumberRangeCondition

func MustNewNumberRangeCondition(start *string, end *string, includeStart, includeEnd bool) *NumberRangeCondition

MustNewNumberRangeCondition panics and must be used only inside goyacc, due it recovers panics into goyacc errors

func (*NumberRangeCondition) GetField

func (q *NumberRangeCondition) GetField() string

GetField .

func (*NumberRangeCondition) SetField

func (q *NumberRangeCondition) SetField(field string)

SetField .

type OrCondition

type OrCondition struct {
	Left  Condition
	Right Condition
}

OrCondition .

func NewOrCondition

func NewOrCondition(left, right Condition) *OrCondition

NewOrCondition .

type RegexpCondition

type RegexpCondition struct {
	Field string
	Value *regexp.Regexp
}

RegexpCondition .

func MustNewRegexpCondition

func MustNewRegexpCondition(s string) *RegexpCondition

MustNewRegexpCondition panics and must be used only inside goyacc, due it recovers panics into goyacc errors

func NewRegexpCondition

func NewRegexpCondition(s string) (*RegexpCondition, error)

NewRegexpCondition .

func (*RegexpCondition) GetField

func (q *RegexpCondition) GetField() string

GetField .

func (*RegexpCondition) SetField

func (q *RegexpCondition) SetField(field string)

SetField .

type TimeRangeCondition

type TimeRangeCondition struct {
	Field        string
	Start        *string
	End          *string
	IncludeStart bool
	IncludeEnd   bool
}

TimeRangeCondition .

func NewTimeRangeCondition

func NewTimeRangeCondition(start, end *string, includeStart, includeEnd bool) *TimeRangeCondition

NewTimeRangeCondition .

func (*TimeRangeCondition) GetField

func (q *TimeRangeCondition) GetField() string

GetField .

func (*TimeRangeCondition) SetField

func (q *TimeRangeCondition) SetField(field string)

SetField .

type WildcardCondition

type WildcardCondition struct {
	Field string
	Value glob.Glob
}

WildcardCondition .

func MustNewWildcardCondition

func MustNewWildcardCondition(s string) *WildcardCondition

MustNewWildcardCondition panics and must be used only inside goyacc, due it recovers panics into goyacc errors

func NewWildcardCondition

func NewWildcardCondition(s string) (*WildcardCondition, error)

NewWildcardCondition .

func (*WildcardCondition) GetField

func (q *WildcardCondition) GetField() string

GetField .

func (*WildcardCondition) SetField

func (q *WildcardCondition) SetField(field string)

SetField .

Jump to

Keyboard shortcuts

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