Documentation
¶
Overview ¶
Package eval is the package to eval the expression and extract the value from the document
Index ¶
- func Query[T XPathNode](document, xpath string, parser func(string) (*T, error), ...) (string, error)
- type BaseExtractor
- func (x *BaseExtractor) Extract() (interface{}, error)
- func (x *BaseExtractor) ExtractBool() (bool, error)
- func (x *BaseExtractor) ExtractDuration() (time.Duration, error)
- func (x *BaseExtractor) ExtractFloat() (float64, error)
- func (x *BaseExtractor) ExtractInt() (int, error)
- func (x *BaseExtractor) ExtractLengthVariable() (any, error)
- func (x *BaseExtractor) ExtractTime() (time.Time, error)
- func (x *BaseExtractor) SetDocument(doc string)
- func (x *BaseExtractor) SetVarType(t VarType)
- type DocType
- type Evaluator
- func (e *Evaluator) AddVariable(v *Variable)
- func (e *Evaluator) CleanVariable()
- func (e *Evaluator) Config() error
- func (e *Evaluator) Evaluate() (bool, error)
- func (e *Evaluator) Extract() error
- func (e *Evaluator) ExtractValue(v *Variable) error
- func (e *Evaluator) SetDocument(t DocType, doc string)
- type Extractor
- type RegexExtractor
- type VarType
- type Variable
- type XPathExtractor
- type XPathNode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BaseExtractor ¶
type BaseExtractor struct { Name string `yaml:"name"` // variable name VarType VarType `yaml:"type"` // variable type Document string `yaml:"-"` DocType DocType `yaml:"-"` XPath string `yaml:"-"` ExtractStrFn func() (string, error) }
BaseExtractor is the base extractor
func (*BaseExtractor) Extract ¶
func (x *BaseExtractor) Extract() (interface{}, error)
Extract extracts the value from the document by xpath expression
func (*BaseExtractor) ExtractBool ¶
func (x *BaseExtractor) ExtractBool() (bool, error)
ExtractBool extracts the value from the document by xpath expression
func (*BaseExtractor) ExtractDuration ¶
func (x *BaseExtractor) ExtractDuration() (time.Duration, error)
ExtractDuration extracts the value from the document by xpath expression
func (*BaseExtractor) ExtractFloat ¶
func (x *BaseExtractor) ExtractFloat() (float64, error)
ExtractFloat extracts the value from the document by xpath expression
func (*BaseExtractor) ExtractInt ¶
func (x *BaseExtractor) ExtractInt() (int, error)
ExtractInt extracts the value from the document by xpath expression
func (*BaseExtractor) ExtractLengthVariable ¶
func (x *BaseExtractor) ExtractLengthVariable() (any, error)
func (*BaseExtractor) ExtractTime ¶
func (x *BaseExtractor) ExtractTime() (time.Time, error)
ExtractTime extracts the value from the document by xpath expression
func (*BaseExtractor) SetDocument ¶
func (x *BaseExtractor) SetDocument(doc string)
SetDocument sets the document
func (*BaseExtractor) SetVarType ¶
func (x *BaseExtractor) SetVarType(t VarType)
SetVarType sets the variable type
type DocType ¶
type DocType int
DocType is the different type of document
func (DocType) MarshalYAML ¶
MarshalYAML is marshal the type
func (*DocType) UnmarshalYAML ¶
UnmarshalYAML is unmarshal the type
type Evaluator ¶
type Evaluator struct { Variables []Variable `` /* 149-byte string literal not displayed */ DocType DocType `` /* 140-byte string literal not displayed */ Expression string `yaml:"expression" json:"expression" jsonschema:"required,title=Expression,description=Expression need to be evaluated"` Document string `yaml:"-" json:"-"` Extractor Extractor `yaml:"-" json:"-"` EvalFuncs map[string]govaluate.ExpressionFunction `yaml:"-" json:"-"` ExtractedValues map[string]interface{} `yaml:"-" json:"-"` }
Evaluator is the structure of evaluator
func NewEvaluator ¶
NewEvaluator is the function to create a evaluator
func (*Evaluator) AddVariable ¶
AddVariable is the function to add a variable
func (*Evaluator) CleanVariable ¶
func (e *Evaluator) CleanVariable()
CleanVariable is the function to clean the variable
func (*Evaluator) ExtractValue ¶
ExtractValue is the function to extract the value from the document
func (*Evaluator) SetDocument ¶
SetDocument is the function to set the document
type Extractor ¶
type Extractor interface { SetQuery(string) SetVarType(VarType) SetDocument(string) Extract() (interface{}, error) }
Extractor is the interface for all extractors
type RegexExtractor ¶
type RegexExtractor struct { BaseExtractor Regex string `yaml:"regex"` // regex expression }
RegexExtractor is a struct for extracting values from a plain string
func NewRegexExtractor ¶
func NewRegexExtractor(document string, docType DocType) *RegexExtractor
NewRegexExtractor creates a new RegexExtractor
func (*RegexExtractor) MatchStr ¶
func (r *RegexExtractor) MatchStr() (string, error)
MatchStr matches the string with the regex expression
func (*RegexExtractor) SetQuery ¶
func (r *RegexExtractor) SetQuery(q string)
SetQuery sets the regex expression
type VarType ¶
type VarType int
VarType is an enum for the different types of values
func (VarType) MarshalYAML ¶
MarshalYAML is marshal the type
func (*VarType) UnmarshalYAML ¶
UnmarshalYAML is unmarshal the type
type Variable ¶
type Variable struct { Name string `yaml:"name" json:"name" jsonschema:"required,title=Variable Name,description=Variable Name"` Type VarType `` /* 179-byte string literal not displayed */ Query string `yaml:"query" json:"query" jsonschema:"required,title=Query,description=XPath/Regex Expression to extract the value"` Value interface{} `yaml:"-" json:"-"` }
Variable is the variable type
type XPathExtractor ¶
type XPathExtractor[T XPathNode] struct { BaseExtractor XPath string `yaml:"xpath"` // xpath expression Parser func(string) (*T, error) Query func(*T, string) (*T, error) Inner func(*T) string }
XPathExtractor is a struct for extracting values from a html/xml/json string
func NewHTMLExtractor ¶
func NewHTMLExtractor(document string, docType DocType) *XPathExtractor[html.Node]
NewHTMLExtractor creates a new HTMLExtractor
func NewJSONExtractor ¶
func NewJSONExtractor(document string, docType DocType) *XPathExtractor[jq.Node]
NewJSONExtractor creates a new JSONExtractor
func NewXMLExtractor ¶
func NewXMLExtractor(document string, docType DocType) *XPathExtractor[xq.Node]
NewXMLExtractor creates a new XMLExtractor
func (*XPathExtractor[T]) ExtractStr ¶
func (x *XPathExtractor[T]) ExtractStr() (string, error)
ExtractStr extracts the value from the document by xpath expression
func (*XPathExtractor[T]) SetQuery ¶
func (x *XPathExtractor[T]) SetQuery(q string)
SetQuery sets the xpath expression