csvtools

package module
v0.0.0-...-d1939f6 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2021 License: Apache-2.0 Imports: 3 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

csvtools Provide tools to work with csv files.

Available tools:

  • Flattener: Flat your structs to csv files and merge them after unmarshal.

Flattener:

How to use?

Marshal

  • Each struct that contains arrays must implement the Record interface.
  • For each array field in your struct add another field with type of your array field's type and also set tag of that array field to dash(-) to ignore for csv. e.g.,
struct Book{
	Authors `csv:"-"` // please note csv tag value is dash.
	Author `csv:"author_,inline"`
}
  • For each Array field in your struct create a new instance of Group and return created groups in the struct as return param of CSVGroups() method.

  • call to DecomposeRecords do decompose your records.

  • Simply call to the csvutil.Marshal method to marshal your list.

Unmarshal

  • Simply use csvutil.Unmarshal to unmarshal your csv records to your struct list.

  • Call to the ComposeRecords to group records and then merge them. it will return array of merged records.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InterfaceToSlice

func InterfaceToSlice(l interface{}) []interface{}

Types

type Group

type Group interface {
	SetVal(r Record, val interface{})
	Val(r Record) interface{}
	ValIsEmpty(r Record) bool
	List(r Record) []interface{}
	SetList(r Record, values []interface{})
}

func NewGroup

func NewGroup(o GroupOpts) Group

type GroupOpts

type GroupOpts struct {
	SetVal     func(r Record, val interface{})
	Val        func(r Record) interface{}
	ValIsEmpty func(r Record) bool
	List       func(r Record) []interface{}
	SetList    func(r Record, values []interface{})
}

type Record

type Record interface {
	CSVKey() interface{}
	CSVGroups() []Group
	CloneEmptyRecord() Record
}

func ComposeGroupedRecords

func ComposeGroupedRecords(records []Record) (Record, error)

func ComposeRecords

func ComposeRecords(records []Record) ([]Record, error)

func DecomposeRecord

func DecomposeRecord(parent Record) ([]Record, error)

func DecomposeRecords

func DecomposeRecords(l []Record) ([]Record, error)

func ToRecordsSlice

func ToRecordsSlice(l interface{}) []Record

type ScanGroupedCSVRecords

type ScanGroupedCSVRecords struct {
	// contains filtered or unexported fields
}

ScanGroupedCSVRecords is a scanner that you can use as bufio.Scanner's splitter. e.g., sc:=bufio.NewScanner() var split ScanGroupedCSVRecords sc.Split(split.SplitFunc)

func (*ScanGroupedCSVRecords) SplitFunc

func (s *ScanGroupedCSVRecords) SplitFunc(data []byte, efo bool) (advance int, token []byte, err error)

Directories

Path Synopsis
examples
group_records command
splitter command

Jump to

Keyboard shortcuts

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