parser

package
v0.0.0-...-e537141 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NegativeOrZeroLength = fmt.Errorf("got negative or zero length for maximum length")

Functions

func CheckLen

func CheckLen(split []string, expected int) (err error)

func ErrorToString

func ErrorToString(ew ErrorWriter, e error) (s string, err error)

func MaxLen

func MaxLen(sec Sections) (maxlen int64, err error)

func MustHave

func MustHave(get Getter, key string) (err error)

func PanicOnErr

func PanicOnErr(err error)

Types

type BinaryReader

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

func NewBinaryReader

func NewBinaryReader(log *zerolog.Logger) (br BinaryReader)

func (BinaryReader) ReadSections

func (br BinaryReader) ReadSections(r io.Reader, sec Sections) (rr ReadResults, err error)

type CreateGetter

type CreateGetter func(Setup, io.Reader) (Getter, error)

type Default

type Default struct{}

func (Default) ParseFloat

func (Default) ParseFloat(s string, size bit.Size) (ff float64, err error)

func (Default) ParseInt

func (Default) ParseInt(s string, base bit.Base, size bit.Size) (ii int64, err error)

func (Default) ParseUInt

func (Default) ParseUInt(s string, base bit.Base, size bit.Size) (ii uint64, err error)

type Delimiter

type Delimiter string

func (Delimiter) AsScanner

func (d Delimiter) AsScanner() (s Scanner)

func (Delimiter) SplitLine

func (d Delimiter) SplitLine(str string) (key, value string, err error)

type Error

type Error struct {
	Line string
	Mode Mode
	// contains filtered or unexported fields
}

func (Error) Error

func (e Error) Error() (s string)

func (Error) Unwrap

func (e Error) Unwrap() (err error)

type ErrorFn

type ErrorFn func(error)

type ErrorUnwrapper

type ErrorUnwrapper string

func (ErrorUnwrapper) ErrorWrite

func (eu ErrorUnwrapper) ErrorWrite(w io.Writer, e error) (n int, err error)

type ErrorWrapper

type ErrorWrapper interface {
	WrapSplitError(line string, err error) error
	WrapParseError(line string, mode Mode, err error) error
}

type ErrorWrapperKind

type ErrorWrapperKind int
const (
	ErrorWrapperSimple ErrorWrapperKind = iota
	ErrorWrapperLogging
)

func (ErrorWrapperKind) New

func (e ErrorWrapperKind) New() (ew ErrorWrapper)

type ErrorWriter

type ErrorWriter interface {
	ErrorWrite(io.Writer, error) (int, error)
}

type Getter

type Getter interface {
	Keys() (keys []string)
	HasKey(key string) (hasKey bool)
	GetParsed(key string) (value string, err error)
}

type InMemoryStorage

type InMemoryStorage map[string]string

func (InMemoryStorage) ToMap

func (in InMemoryStorage) ToMap() (m Map)

type Len

type Len int64

type Locations

type Locations map[string]*time.Location

type LogErrorWrap

type LogErrorWrap struct {
	Wrapper ErrorWrapper
	Logger  *log.Logger
}

func (LogErrorWrap) LogContext

func (l LogErrorWrap) LogContext(ctx string, e error, fn WrapFunc) (err error)

func (LogErrorWrap) WrapParseError

func (l LogErrorWrap) WrapParseError(line string, mode Mode, e error) (err error)

func (LogErrorWrap) WrapSplitError

func (l LogErrorWrap) WrapSplitError(line string, e error) (err error)

type Map

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

func EmptyMap

func EmptyMap() (m Map)

func NewMap

func NewMap(s Setup, r io.Reader) (m Map, err error)

func ParseMap

func ParseMap(mm MapManager, s Setup, r io.Reader) (m *Map, err error)

func (Map) GetParsed

func (m Map) GetParsed(key string) (val string, err error)

func (Map) HasKey

func (m Map) HasKey(key string) (hasKey bool)

func (Map) Keys

func (m Map) Keys() (keys []string)

func (*Map) Reset

func (m *Map) Reset()

func (*Map) SetParsed

func (m *Map) SetParsed(key, val string) (err error)

type MapManager

type MapManager interface {
	GetMap() *Map
	PutMap(m *Map)
}

type MapPool

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

func NewMapPool

func NewMapPool() (mp *MapPool)

func (*MapPool) GetMap

func (mm *MapPool) GetMap() (m *Map)

func (*MapPool) PutMap

func (mm *MapPool) PutMap(m *Map)

type MissingKey

type MissingKey struct {
	Key string
}

func (MissingKey) Error

func (m MissingKey) Error() (s string)

type Mode

type Mode int
const (
	ModeInt Mode = iota
	ModeUint
	ModeFloat
)

func (Mode) String

func (m Mode) String() (s string)

func (Mode) WrapError

func (m Mode) WrapError(ew ErrorWrapper, s string, e error) (err error)

type MutGetter

type MutGetter interface {
	Setter
	Getter
}

type NoMatchedLayout

type NoMatchedLayout struct {
	LastError error
}

func (NoMatchedLayout) Error

func (n NoMatchedLayout) Error() (s string)

func (NoMatchedLayout) Unwrap

func (n NoMatchedLayout) Unwrap() (err error)

type Parser

type Parser interface {
	ParseInt(string, bit.Base, bit.Size) (int64, error)
	ParseUint(string, bit.Base, bit.Size) (uint64, error)
	ParseFloat(string, bit.Size) (float64, error)
	ParseBool(string) (bool, error)
}

type ReadResults

type ReadResults map[string]string

func ReadSections

func ReadSections(r io.Reader, sections Sections) (rr ReadResults, err error)

type ReaderHandler

type ReaderHandler interface {
	HandleReaders(readers []SectionReader) (r ReadResults, err error)
}

type ReaderWrapper

type ReaderWrapper interface {
	WrapReader(io.Reader) (*bufio.Scanner, error)
}

type Scanner

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

func (Scanner) SplitLine

func (s Scanner) SplitLine(str string) (key, value string, err error)

type Section

type Section struct {
	ID   string
	Kind SectionKind
	Len  Len
}

func ReadSection

func ReadSection(ID string, length Len) (s Section)

func SkipSection

func SkipSection(ID string, length Len) (s Section)

type SectionHandler

type SectionHandler interface {
	HandleSection(r io.Reader, sec Section, rr ReadResults) (err error)
}

type SectionKind

type SectionKind int
const (
	SectionRead SectionKind = iota
	SectionSkip
	TotalSections
)

type SectionReader

type SectionReader interface {
	ReadSections(r io.Reader, sections Sections) (rr ReadResults, err error)
}

type Sections

type Sections []Section

type Setter

type Setter interface {
	SetParsed(key, value string) error
}

type Setup

type Setup struct {
	Splitter Splitter
	Wrapper  ReaderWrapper
}

func (Setup) ParseInto

func (s Setup) ParseInto(r io.Reader, setter Setter) (err error)

type SimpleErrorWrapper

type SimpleErrorWrapper struct{}

func (SimpleErrorWrapper) WrapParseError

func (SimpleErrorWrapper) WrapParseError(line string, mode Mode, err error) (e error)

func (SimpleErrorWrapper) WrapSplitError

func (SimpleErrorWrapper) WrapSplitError(line string, err error) (e error)

type SplitError

type SplitError struct {
	Line string
	// contains filtered or unexported fields
}

func (SplitError) Error

func (s SplitError) Error() (str string)

func (SplitError) Unwrap

func (s SplitError) Unwrap() (err error)

type SplitWrapErr

type SplitWrapErr struct {
	Splitter Splitter
	Wrapper  ErrorWrapper
}

func (SplitWrapErr) SplitLine

func (s SplitWrapErr) SplitLine(str string) (key, value string, err error)

type Splitter

type Splitter interface {
	SplitLine(string) (key, value string, err error)
}

type TeeGetter

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

Wrapper for reading from many Retreivers. It will try to read the appropriate parameters from each of the receivers. Returns with error if parameter could not be found in any of them.

func NewTeeGetter

func NewTeeGetter(getters ...Getter) (t TeeGetter)

func (TeeGetter) Get

func (t TeeGetter) Get(key string) (s string, err error)

type TestCase

type TestCase struct {
	Input    string
	Expected Getter
}

func (TestCase) Test

func (tc TestCase) Test(t *testing.T, s Setup, creator CreateGetter)

func (TestCase) TestErr

func (tc TestCase) TestErr(s Setup, creator CreateGetter) (err error)

type TestWithSetup

type TestWithSetup struct {
	Cases []TestCase
	Setup Setup
}

func (TestWithSetup) ForEach

func (ts TestWithSetup) ForEach(fn ErrorFn, creator CreateGetter)

func (TestWithSetup) Test

func (ts TestWithSetup) Test(t *testing.T, creator CreateGetter)

func (TestWithSetup) TestErr

func (ts TestWithSetup) TestErr(creator CreateGetter) (err error)

type Time

type Time interface {
	ParseTime(dateStr string) (date time.Time, err error)
}

type TimeLayouts

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

func NewLayouts

func NewLayouts(layouts ...string) (t TimeLayouts)

func (TimeLayouts) ParseTime

func (t TimeLayouts) ParseTime(dateStr string) (date time.Time, err error)

type TimeZone

type TimeZone interface {
	ParseTimeZone(str string) (loc *time.Location, err error)
}

type WrapError

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

func (WrapError) ParseFloat

func (we WrapError) ParseFloat(s string, size bit.Size) (fl float64, err error)

func (WrapError) ParseInt

func (we WrapError) ParseInt(s string, base bit.Base, size bit.Size) (ii int64, err error)

func (WrapError) ParseUint

func (we WrapError) ParseUint(s string, base bit.Base, size bit.Size) (ii uint64, err error)

type WrapFunc

type WrapFunc func(error) error

type WrapScanner

type WrapScanner struct{}

func WrapIntoScanner

func WrapIntoScanner() (w WrapScanner)

func (WrapScanner) WrapReader

func (WrapScanner) WrapReader(r io.Reader) (b *bufio.Scanner, err error)

type WrongElementNumber

type WrongElementNumber struct {
	Delimiter
	Expected, Got int
}

func (WrongElementNumber) Error

func (w WrongElementNumber) Error() (s string)

Jump to

Keyboard shortcuts

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