Documentation
¶
Overview ¶
Package transformer provides functionality for transforming and parsing data.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TextParser ¶
type TextParser struct {
// contains filtered or unexported fields
}
TextParser provides functionality to parse various text formats (JSON, XML, plain text) and extract data into a structured map. It uses a configuration map to define the extraction rules for each format, such as JSONPath for JSON, XPath for XML, and regex for plain text.
func NewTextParser ¶
func NewTextParser() *TextParser
NewTextParser creates and returns a new instance of TextParser.
func (*TextParser) Parse ¶
func (p *TextParser) Parse(inputType string, input []byte, config map[string]string) (map[string]any, error)
Parse extracts data from an input byte slice based on the specified input type and configuration.
inputType specifies the format of the input data ("json", "xml", or "text"). input is the raw byte slice containing the data to be parsed. config is a map where keys are the desired output keys and values are the extraction rules (JSONPath, XPath, or regex) for the corresponding data. It returns a map containing the extracted data or an error if parsing fails.
func (*TextParser) Transform ¶
Transform takes a map of data and a Go template string and returns a byte slice containing the transformed output.
templateStr is the Go template to be executed. data is the map containing the data to be used in the template. It returns the transformed data as a byte slice or an error if the transformation fails.
type TextTemplate ¶
type TextTemplate struct {
// contains filtered or unexported fields
}
TextTemplate provides a simple wrapper around Go's standard text/template for rendering strings with dynamic data.
func NewTemplate ¶
func NewTemplate(templateString, startTag, endTag string) (*TextTemplate, error)
NewTemplate parses a template string and creates a new TextTemplate.
templateString is the template content to be parsed. It returns a new TextTemplate or an error if the template string is invalid.
func (*TextTemplate) Render ¶
func (t *TextTemplate) Render(params map[string]any) (string, error)
Render executes the template with the provided parameters and returns the resulting string.
params is a map of key-value pairs that will be available within the template. It returns the rendered string or an error if the template execution fails.
type Transformer ¶
type Transformer struct {
// contains filtered or unexported fields
}
Transformer provides functionality to transform a map of data into a structured string using a Go template. It supports multiple output formats specified by the template, such as JSON, XML, or plain text.
func NewTransformer ¶
func NewTransformer() *Transformer
NewTransformer creates and returns a new instance of Transformer.
func (*Transformer) Transform ¶
Transform takes a map of data and a Go template string and returns a byte slice containing the transformed output.
templateStr is the Go template to be executed. data is the map containing the data to be used in the template. It returns the transformed data as a byte slice or an error if the transformation fails.