parser

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: MIT Imports: 25 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 CreateFileStorageField added in v1.0.1

func CreateFileStorageField(parsedValue builder.Interfacable, index *uint32, input builder.Interfacable, cfg *config.FileStorageField, logger logger.Logger) (string, error)

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, input builder.Interfacable) builder.Interfacable

func FillArrayBaseField added in v0.0.34

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

func FillArrayObjectField added in v0.0.34

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

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 ProcessFileField added in v0.0.23

func ProcessFileField(parsedValue builder.Interfacable, index *uint32, input builder.Interfacable, 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.Interfacable, index *uint32, input builder.Interfacable) (*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 json.RawMessage
}

func (*ParseResult) IsEmpty added in v0.0.6

func (p *ParseResult) IsEmpty() bool

func (*ParseResult) Raw

func (p *ParseResult) Raw() json.RawMessage

func (*ParseResult) ToInterface added in v1.0.0

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

func (*ParseResult) ToJson

func (p *ParseResult) ToJson() string

type Parser

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

Jump to

Keyboard shortcuts

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