etldata

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package data holds custom types and functions for passing JSON between stages.

Index

Examples

Constants

View Source
const (
	DefaultTimeLayout = "2006-01-02 15:04:05"
	FullDateLayout    = "January 2, 2006"
	ShortDateLayout   = "Jan 2, 2006"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

type Bool bool

Bool supports both 1/0 and true/false

func (Bool) MarshalJSON

func (b Bool) MarshalJSON() ([]byte, error)

func (*Bool) UnmarshalJSON

func (b *Bool) UnmarshalJSON(d []byte) (err error)

type JSON

type JSON []byte

JSON is the data type that is passed along all data channels. Under the covers, JSON is simply a []byte containing JSON data.

func JSONFromHeaderAndRows

func JSONFromHeaderAndRows(header []string, rows [][]interface{}) (JSON, error)

JSONFromHeaderAndRows takes the given header and rows of values, and turns it into a JSON array of objects.

Example
package main

import (
	"fmt"

	"github.com/teambenny/goetl/etldata"
)

func main() {
	header := []string{"A", "B", "C"}
	rows := [][]interface{}{
		[]interface{}{1, 2, 3},
		[]interface{}{4, 5, 6},
	}

	d, _ := etldata.JSONFromHeaderAndRows(header, rows)

	fmt.Println(fmt.Sprintf("%+v", string(d)))
}
Output:

[{"A":1,"B":2,"C":3},{"A":4,"B":5,"C":6}]

func NewJSON

func NewJSON(v interface{}) (JSON, error)

NewJSON is a simple wrapper for json.Marshal.

Example
package main

import (
	"fmt"

	"github.com/teambenny/goetl/etldata"
)

type testStruct struct {
	A int
	B int
}

func main() {
	t := testStruct{A: 1, B: 2}

	d, _ := etldata.NewJSON(t)

	fmt.Println(string(d))
}
Output:

{"A":1,"B":2}

func (JSON) Bytes

func (d JSON) Bytes() []byte

Bytes implements Payload interface.

func (JSON) Clone

func (d JSON) Clone() Payload

Clone implements Payload interface.

func (JSON) Objects

func (d JSON) Objects() ([]map[string]interface{}, error)

Objects implements Payload interface.

func (JSON) Parse

func (d JSON) Parse(v interface{}) error

Parse implements Payload interface. It is a simple wrapper for json.Unmarshal.

func (JSON) ParseSilent

func (d JSON) ParseSilent(v interface{}) error

ParseSilent implements Payload interface.

type Payload

type Payload interface {
	// Parse transforms the bytes into a struct. It should log
	// output when unmarshaling fails.
	Parse(v interface{}) error

	// ParseSilent should not log output when unmarshaling fails.
	// It can be used in cases where failure is expected.
	ParseSilent(v interface{}) error

	// Objects is a helper for parsing into a slice of
	// generic maps/objects. The use-case is when a stage is expecting
	// to receive either an object or an array of objects, and
	// we want to deal with it in a generic fashion.
	Objects() ([]map[string]interface{}, error)

	// Bytes returns the byte representation of the underlying payload.
	Bytes() []byte

	// Clone returns a new instance of the Payload to send to
	// multiple processors (to prevent race conditions)
	Clone() Payload
}

Payload is how data flows through pipelines.

type SQLTime

type SQLTime struct {
	time.Time
}

func (SQLTime) Format

func (t SQLTime) Format(layout string) string

func (*SQLTime) In

func (t *SQLTime) In(l *time.Location) *SQLTime

func (*SQLTime) IsZero

func (t *SQLTime) IsZero() bool

func (SQLTime) MarshalJSON

func (t SQLTime) MarshalJSON() ([]byte, error)

func (SQLTime) String

func (t SQLTime) String() string

func (*SQLTime) UTCTime

func (t *SQLTime) UTCTime() *SQLTime

func (*SQLTime) UnmarshalJSON

func (t *SQLTime) UnmarshalJSON(d []byte) (err error)

Jump to

Keyboard shortcuts

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