parser

package
v0.0.42 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: MIT Imports: 24 Imported by: 0

README

Parsers

Package is responsible for parsing data out of connectors, next parsers a supported:

  1. HTML
  2. JSON
  3. XPath
  4. XML(In progress)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FillArrayArrayField added in v0.0.34

func FillArrayArrayField[T comparable](engine *engineParser[T], parent []T, size int, fn func(T, string) []T, cfg *config.ArrayConfig) builder.Jsonable

func FillArrayBaseField added in v0.0.34

func FillArrayBaseField[T comparable](engine *engineParser[T], parent []T, size int, cfg *config.BaseField) builder.Jsonable

func FillArrayObjectField added in v0.0.34

func FillArrayObjectField[T comparable](engine *engineParser[T], parent []T, size int, cfg *config.ObjectConfig) builder.Jsonable

func IsZero added in v0.0.34

func IsZero[T comparable](v T) bool

func NewHTML added in v0.0.34

func NewHTML(body []byte, logger logger.Logger) *engineParser[*goquery.Selection]

func NewJson added in v0.0.34

func NewJson(body []byte, logger logger.Logger) *engineParser[*gjson.Result]

func NewXML added in v0.0.35

func NewXML(body []byte, logger logger.Logger) *engineParser[*xmlquery.Node]

func NewXPath added in v0.0.34

func NewXPath(body []byte, logger logger.Logger) *engineParser[*html.Node]

func ProcessExpression added in v0.0.19

func ProcessExpression(expression string, result builder.Jsonable, index *uint32) (interface{}, error)

func ProcessFileField added in v0.0.23

func ProcessFileField(parsedValue builder.Jsonable, index *uint32, field *config.FileFieldConfig, logger logger.Logger) (string, error)

Types

type Engine added in v0.0.29

type Engine interface {
	Get(model *config.Model, parsedValue builder.Jsonable, index *uint32) (*ParseResult, error)
}

func NewEngine added in v0.0.29

func NewEngine(cfg *config.ConnectorConfig, logger logger.Logger) Engine

type Factory

type Factory func([]byte, logger.Logger) Parser
var (
	JsonFactory Factory = func(bytes []byte, logger logger.Logger) Parser {
		return NewJson(bytes, logger.With("parser", "json"))
	}

	HTMLFactory Factory = func(bytes []byte, logger logger.Logger) Parser {
		return NewHTML(bytes, logger.With("parser", "html"))
	}

	XPathFactory Factory = func(bytes []byte, logger logger.Logger) Parser {
		return NewXPath(bytes, logger.With("parser", "xpath"))
	}

	XMLFactory Factory = func(bytes []byte, logger logger.Logger) Parser {
		return NewXML(bytes, logger.With("parser", "xml"))
	}
)

type ParseResult

type ParseResult struct {
	Json      string `json:"raw"`
	RawResult interface{}
}

func (*ParseResult) IsEmpty added in v0.0.6

func (p *ParseResult) IsEmpty() bool

func (*ParseResult) Raw

func (p *ParseResult) Raw() interface{}

func (*ParseResult) ToJson

func (p *ParseResult) ToJson() string

type Parser

type Parser interface {
	Parse(model *config.Model) (*ParseResult, error)
}

Jump to

Keyboard shortcuts

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