csv

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCSVDecoder

func NewCSVDecoder(conf engine.DecoderConfig) engine.Decoder

func NewCSVEncoder

func NewCSVEncoder(c engine.EncoderConfig) engine.Encoder

func StringFields

func StringFields(r engine.Record) []string

func StringFieldsWithFormat

func StringFieldsWithFormat(r engine.Record, tf *engine.Timeformatter, decimal int) []string

Types

type CSVDecoder

type CSVDecoder struct {
	engine.DecoderConfig
	// contains filtered or unexported fields
}

func (*CSVDecoder) Decode

func (cr *CSVDecoder) Decode() ([]engine.Record, error)

type CSVEncoder

type CSVEncoder struct {
	engine.EncoderConfig
	// contains filtered or unexported fields
}
Example
package main

import (
	"time"

	"github.com/OutOfBedlam/tine/engine"
	_ "github.com/OutOfBedlam/tine/plugin/codec/csv"
	_ "github.com/OutOfBedlam/tine/plugin/codec/json"
	_ "github.com/OutOfBedlam/tine/plugin/flows/base"
	_ "github.com/OutOfBedlam/tine/plugin/inlets/file"
	_ "github.com/OutOfBedlam/tine/plugin/outlets/file"
)

func main() {
	dsl := `
	[[inlets.file]]
		data = [
			"a,1,1.234,true,2024/08/09 16:01:02", 
			"b,2,2.345,false,2024/08/09 16:03:04", 
			"c,3,3.456,true,2024/08/09 16:05:06",
		]
		format = "csv"
		timeformat = "2006/01/02 15:04:05"
		tz = "UTC"
		fields = ["area","ival","fval","bval","tval"]
		types  = ["string", "int", "float", "bool", "time"]
	[[flows.select]]
		includes = ["#*", "ival", "area", "ival", "fval", "bval", "tval"]
	[[outlets.file]]
		path = "-"
		format = "csv"
	`
	// Mock the current time
	count := int64(0)
	engine.Now = func() time.Time { count++; return time.Unix(1721954797+count, 0) }

	// Create a new pipeline
	pipeline, err := engine.New(engine.WithConfig(dsl))
	if err != nil {
		panic(err)
	}
	if err := pipeline.Run(); err != nil {
		panic(err)
	}
}
Output:

file,1721954798,1,a,1,1.234,true,1723219262
file,1721954799,2,b,2,2.345,false,1723219384
file,1721954800,3,c,3,3.456,true,1723219506

func (*CSVEncoder) Encode

func (cw *CSVEncoder) Encode(recs []engine.Record) error

Jump to

Keyboard shortcuts

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