filtercsv

package module
v0.0.0-...-283e4ee Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: MIT Imports: 4 Imported by: 0

README

GoDoc

Package filtercsv is a helper to filter a csv file.

It assumes the csv has a header row with column names.

It makes it easy (well, easier) to keep only specific columns and rows.

Maybe someday it'll grow a command line interface. Maybe.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Process

func Process(r *csv.Reader, w *csv.Writer, cfg *Config) (err error)

Types

type Config

type Config struct {
	KeepCol   func(name string) bool
	KeepRow   func(r *Row) bool
	ModifyRow func(r *Row)
}

type Reader

type Reader struct {
	Header []string // populated during first call to Read
	// contains filtered or unexported fields
}

A Reader reads a CSV that has a header row, yielding rows that can be queried by header title. It doesn't really semantically belong in something called "filtercsv". Oh well.

func NewReader

func NewReader(r *csv.Reader) *Reader

NewReader returns a *Reader that wraps r.

func (*Reader) Read

func (r *Reader) Read() (*Row, error)

Read returns a single row from the CSV. It does not return a separate header row. If you want to do something with the header row, after the first call to read, use r.Header.

type Row

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

func (*Row) Field

func (r *Row) Field(name string) string

func (*Row) SetField

func (r *Row) SetField(name, value string)

Jump to

Keyboard shortcuts

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