rexon

package module
v0.0.0-...-8965f1e Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2018 License: Apache-2.0 Imports: 13 Imported by: 7

README

Rexon Build Status Go Report Card

A helper library for extracting json documents from unstructured data.

TODO

  • Documentation
  • Examples

Written by Bruno Moura brunotm@gmail.com

Documentation

Index

Constants

View Source
const (
	Number      ValueType = "number"
	String      ValueType = "string"
	Bool        ValueType = "bool"
	Time        ValueType = "time"
	Duration    ValueType = "duration"
	DigitalUnit ValueType = "digital_unit"

	// Decimal
	Byte = 1
	KB   = Byte * 1000
	MB   = KB * 1000
	GB   = MB * 1000
	TB   = GB * 1000
	PB   = TB * 1000

	// Binary
	KiB = Byte * 1024
	MiB = KiB * 1024
	GiB = MiB * 1024
	TiB = GiB * 1024
	PiB = TiB * 1024
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DataParser

type DataParser interface {
	Parse(ctx context.Context, data io.Reader) (results <-chan Result)
	ParseBytes(ctx context.Context, data []byte) (results <-chan Result)
}

DataParser interface

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser type

func MustNewParser

func MustNewParser(values []*Value, options ...ParserOpt) (p *Parser)

MustNewParser is like NewParser but panics on error

func NewParser

func NewParser(values []*Value, options ...ParserOpt) (p *Parser, err error)

NewParser creates a new Parser

func (*Parser) Parse

func (p *Parser) Parse(ctx context.Context, data io.Reader) (results <-chan Result)

Parse parses raw data using the specified Rex

func (*Parser) ParseBytes

func (p *Parser) ParseBytes(ctx context.Context, data []byte) (results <-chan Result)

ParseBytes parses raw data using the specified RexLine

type ParserOpt

type ParserOpt func(*Parser) (err error)

ParserOpt functional options for Parser

func ContinueTag

func ContinueTag(expr string) (opt ParserOpt)

ContinueTag sets a regexp that when match the parser will resume after SkipTag

func FindAll

func FindAll() (opt ParserOpt)

FindAll successive matches for the specified LineRegex

func LineRegex

func LineRegex(expr string) (opt ParserOpt)

LineRegex sets a regexp for this parser making the extraction to work in line mode and ignore all Values regexps. Working in line mode is much faster than in Set using Value regexp. Multiline regexps `(?m)` are still valid, but usually are slower than using Values regexps.

func SkipTag

func SkipTag(expr string) (opt ParserOpt)

SkipTag sets a regexp that when match the parser will skip lines until ContinueTag

func StartTag

func StartTag(expr string) (opt ParserOpt)

StartTag sets a regexp that will be used to start the match and extract when working in Set mode (Value regexp)

func StopTag

func StopTag(expr string) (opt ParserOpt)

StopTag sets a regexp that when match will stop the parser

func TrimSpaces

func TrimSpaces() (opt ParserOpt)

TrimSpaces trims right and left trailing spaces

type Result

type Result struct {
	Data   []byte
	Errors []error
}

Result type for each extracted JSON data and associated parse errors

type Value

type Value struct {
	// contains filtered or unexported fields
}

Value represent each singular value to extract, parse and transform

func MustNewValue

func MustNewValue(name string, vt ValueType, options ...ValueOpt) (v *Value)

MustNewValue is like NewValue but panics on error

func NewValue

func NewValue(name string, vt ValueType, options ...ValueOpt) (v *Value, err error)

NewValue creates a new value parser

func (*Value) Name

func (v *Value) Name() (name string)

Name returns this value name

func (*Value) Parse

func (v *Value) Parse(b []byte) (value interface{}, matched bool, err error)

Parse parses the value for the given byte. Uses the ValueRegex if specified to first extract the data

type ValueOpt

type ValueOpt func(*Value) (err error)

ValueOpt functional options for Value

func FromFormat

func FromFormat(format string) (opt ValueOpt)

FromFormat sets the from format for this value parser

func Nullable

func Nullable() (opt ValueOpt)

Nullable sets the value to null on parsing errors and ignores the error

func Round

func Round(round int) (opt ValueOpt)

Round sets the round for this value parser, defaults to 2 if not specified

func ToFormat

func ToFormat(format string) (opt ValueOpt)

ToFormat sets the destination format for this value parser

func ValueRegex

func ValueRegex(expr string) (opt ValueOpt)

ValueRegex sets the regexp for this value parser

type ValueParser

type ValueParser interface {
	Parse(b []byte) (value interface{}, matched bool, err error)
}

ValueParser interface

type ValueType

type ValueType string

Jump to

Keyboard shortcuts

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