jsonline

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2021 License: GPL-3.0 Imports: 13 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 LcFirst added in v0.5.0

func LcFirst(str string) string

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.
	Date                    // Date without zone info, e.g. : "2006-01-02".
	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)
	GetOrNil(key string) interface{}
	GetAtIndex(index int) (interface{}, bool)
	GetAtIndexOrNil(index int) interface{}
	Set(key string, val interface{})
	SetAtIndex(index int, val interface{})
	Len() int
	Iter() func() (string, interface{}, bool)

	GetString(key string) string
	GetInt(key string) int
	GetInt64(key string) int64
	GetInt32(key string) int32
	GetInt16(key string) int16
	GetInt8(key string) int8
	GetUint(key string) uint
	GetUint64(key string) uint64
	GetUint32(key string) uint32
	GetUint16(key string) uint16
	GetUint8(key string) uint8
	GetFloat64(key string) float64
	GetFloat32(key string) float32
	GetBool(key string) bool
	GetBytes(key string) []byte
	GetTime(key string) time.Time

	ImportAtKey(key string, val interface{}) error
	ImportAtIndex(index int, val interface{}) error

	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)

	MapTo(interface{})
}

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
	WithDate(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
	WithMappedDate(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 NewValueDate added in v0.5.0

func NewValueDate(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