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 (*Bool) UnmarshalJSON ¶
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 ¶
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 ¶
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) ParseSilent ¶
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.
Click to show internal directories.
Click to hide internal directories.