jsonline

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2021 License: GPL-3.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupportedFormat     = errors.New("unsupported format")
	ErrUnsupportedImportType = errors.New("can't import type")
	ErrUnsupportedExportType = errors.New("can't export type")
)

Functions

func DefaultProcessor

func DefaultProcessor(r Row, e error) error

func NoFailureProcessor

func NoFailureProcessor(r Row, e error) error

Types

type Exporter

type Exporter interface {
	WithTemplate(Template) Exporter
	Export(interface{}) error
}

func NewExporter

func NewExporter(w io.Writer) Exporter

type Format

type Format int8
const (
	String    Format = iota // String representation, e.g. : "hello", "2.4", "true".
	Numeric                 // Numeric (integer or decimal), e.g. : 2.4, 1.
	Boolean                 // Boolean : true or false.
	Binary                  // Binary representation encoded as base64.
	DateTime                // DateTime as RFC3339, e.g. : "2006-01-02T15:04:05Z", "2006-01-02T15:04:05+07:00".
	Timestamp               // Timestamp the number of seconds since 1970 ("UNIX time").
	Auto                    // Auto columns have no specific format enforced.
	Hidden                  // Hidden columns will not be exported in jsonline.
)

type Importer

type Importer interface {
	WithTemplate(Template) Importer
	Import() bool
	GetRow() (Row, error)
}

func NewImporter

func NewImporter(r io.Reader) Importer

type Processor

type Processor func(Row, error) error

type RawType added in v0.3.0

type RawType interface{}

type Row

type Row interface {
	Value

	Has(key string) bool
	Get(key string) (interface{}, bool)
	GetAtIndex(index int) (interface{}, bool)
	Set(key string, val interface{}) error
	SetAtIndex(index int, val interface{}) error
	Len() int
	Iter() func() (string, interface{}, bool)

	GetValue(key string) (Value, bool)
	GetValueAtIndex(index int) (Value, bool)
	SetValue(key string, val Value) Row
	SetValueAtIndex(index int, val Value) Row
	IterValues() func() (string, Value, bool)
}

func CloneRow

func CloneRow(r Row) Row

func NewRow

func NewRow() Row

NewRow create a new Row.

type Streamer

type Streamer interface {
	WithProcessor(Processor) Streamer
	Stream() error
}

func NewStreamer

func NewStreamer(importer Importer, exporter Exporter) Streamer

type Template

type Template interface {
	WithString(name string) Template
	WithNumeric(name string) Template
	WithBoolean(name string) Template
	WithBinary(name string) Template
	WithDateTime(name string) Template
	WithTimestamp(name string) Template
	WithAuto(name string) Template
	WithHidden(name string) Template
	WithRow(name string, row Template) Template

	WithMappedString(name string, rawtype RawType) Template
	WithMappedNumeric(name string, rawtype RawType) Template
	WithMappedBoolean(name string, rawtype RawType) Template
	WithMappedBinary(name string, rawtype RawType) Template
	WithMappedDateTime(name string, rawtype RawType) Template
	WithMappedTimestamp(name string, rawtype RawType) Template
	WithMappedAuto(name string, rawtype RawType) Template

	With(name string, format Format, rawtype RawType) Template

	CreateRow(interface{}) (Row, error)
	CreateRowEmpty() Row

	GetExporter(io.Writer) Exporter
	GetImporter(io.Reader) Importer
}

func NewTemplate

func NewTemplate() Template

type Value

type Value interface {
	GetFormat() Format
	GetRawType() RawType

	Raw() interface{}

	Export() (interface{}, error)
	Import(interface{}) error

	json.Unmarshaler
	json.Marshaler
	fmt.Stringer

	DebugString() string
}

func CloneValue

func CloneValue(v Value) Value

func NewValue

func NewValue(v interface{}, f Format, rawtype RawType) Value

func NewValueAuto

func NewValueAuto(v interface{}) Value

func NewValueBinary

func NewValueBinary(v interface{}) Value

func NewValueBoolean

func NewValueBoolean(v interface{}) Value

func NewValueDateTime

func NewValueDateTime(v interface{}) Value

func NewValueHidden

func NewValueHidden(v interface{}) Value

func NewValueNil

func NewValueNil(f Format, rawtype RawType) Value

func NewValueNumeric

func NewValueNumeric(v interface{}) Value

func NewValueString

func NewValueString(v interface{}) Value

func NewValueTimestamp

func NewValueTimestamp(v interface{}) Value

Jump to

Keyboard shortcuts

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