Documentation ¶
Overview ¶
Package sv includes iterators for reading from separated-values sources and writing using separated-values formats, such as CSV and TSV.
Index ¶
- Constants
- Variables
- func CreateHeaderAndKnownKeys(object interface{}, sorted bool, reversed bool) ([]interface{}, map[interface{}]struct{})
- func CreateHeaderAndKnownKeysFromValue(objectValue reflect.Value, sorted bool, reversed bool) ([]interface{}, map[interface{}]struct{})
- func ExpandHeader(header []interface{}, knownKeys map[interface{}]struct{}, object reflect.Value, ...) ([]interface{}, map[interface{}]struct{})
- func ExpandHeaderWithWildcard(header []interface{}, knownKeys map[interface{}]struct{}, object reflect.Value, ...) ([]interface{}, map[interface{}]struct{})
- func FillRight(row []string, n int) []string
- func FormatToSeparator(format string) (rune, error)
- func GetKeys(object interface{}, sorted bool) []interface{}
- func GetKeysFromValue(m reflect.Value, sorted bool) []interface{}
- func Read(input *ReadInput) (interface{}, error)
- func RemoveWildcard(header []interface{}) []interface{}
- func SortTable(header []string, rows [][]string, reversed bool) ([]string, [][]string)
- func TestFillRight(t *testing.T)
- func ToRow(object interface{}, columns []interface{}, ...) ([]string, error)
- func ToRowFromValue(objectValue reflect.Value, columns []interface{}, ...) ([]string, error)
- func Write(input *WriteInput) error
- func WriteTable(input *WriteTableInput) error
- type ErrInvalidFormat
- type Flusher
- type Iterator
- type NewIteratorInput
- type ReadInput
- type Row
- type WriteInput
- type WriteTableInput
- type Writer
Constants ¶
const (
Wildcard = "*"
)
Variables ¶
var (
DefaultType = reflect.TypeOf(map[string]string{})
)
Functions ¶
func CreateHeaderAndKnownKeys ¶
func CreateHeaderAndKnownKeys(object interface{}, sorted bool, reversed bool) ([]interface{}, map[interface{}]struct{})
CreateHeaderAndKnownKeys returns an object's keys or field names as a slice and set.
func CreateHeaderAndKnownKeysFromValue ¶
func CreateHeaderAndKnownKeysFromValue(objectValue reflect.Value, sorted bool, reversed bool) ([]interface{}, map[interface{}]struct{})
CreateHeaderAndKnownKeysFromValue returns an object's keys or field names as a slice and set.
func ExpandHeader ¶
func ExpandHeader(header []interface{}, knownKeys map[interface{}]struct{}, object reflect.Value, sorted bool, reversed bool) ([]interface{}, map[interface{}]struct{})
ExpandHeader expands a table header with the keys from the given object.
func ExpandHeaderWithWildcard ¶
func ExpandHeaderWithWildcard(header []interface{}, knownKeys map[interface{}]struct{}, object reflect.Value, sorted bool, reversed bool) ([]interface{}, map[interface{}]struct{})
ExpandHeaderWithWildcard expands a table header at the wildcard position with keys from the object.
func FormatToSeparator ¶
FormatToSeparator converts a format into its corresponding separator.
func GetKeys ¶
func GetKeys(object interface{}, sorted bool) []interface{}
GetKeys returns the keys for a map as an []interface{}. If you want the keys to be sorted in alphabetical order, pass sorted equal to true.
func GetKeysFromValue ¶
GetKeysFromValue returns the keys for a map as an []interface{}. If you want the keys to be sorted in alphabetical order, pass sorted equal to true.
func RemoveWildcard ¶
func RemoveWildcard(header []interface{}) []interface{}
func SortTable ¶
SortTable sorts the table columns alphabetically. If reversed is true, then sorts in reverse alphabetical order.
func TestFillRight ¶
func ToRow ¶
func ToRow(object interface{}, columns []interface{}, valueSerializer func(object interface{}) (string, error)) ([]string, error)
ToRow converts an object into a row of strings and returns an error, if any.
func ToRowFromValue ¶
func ToRowFromValue(objectValue reflect.Value, columns []interface{}, valueSerializer func(object interface{}) (string, error)) ([]string, error)
ToRow converts an object into a row of strings and returns an error, if any.
func Write ¶
func Write(input *WriteInput) error
Write writes the given object(s) as separated values, e.g., CSV or T If the type of the input object is of kind Array or Slice, then writes each object on its own line. Otherwise, just writes a CSV with a header and one row for the object.
func WriteTable ¶
func WriteTable(input *WriteTableInput) error
WriteTable writes the given rows as separated values.
Types ¶
type ErrInvalidFormat ¶
type ErrInvalidFormat struct {
Format string
}
ErrInvalidFormat indicates an invalid format was given
func (*ErrInvalidFormat) Error ¶
func (e *ErrInvalidFormat) Error() string
Error returns the string representation of the error.
type Iterator ¶
type Iterator struct { Reader *csv.Reader Type reflect.Type // contains filtered or unexported fields }
func NewIterator ¶
func NewIterator(input *NewIteratorInput) (*Iterator, error)
type NewIteratorInput ¶
type NewIteratorInput struct { Reader io.Reader Type reflect.Type // required Separator rune // the values separator Header []interface{} SkipLines int Comment string LazyQuotes bool Limit int }
Input for NewIterator function.
type ReadInput ¶
type ReadInput struct { Type reflect.Type // the output type Reader io.Reader Separator rune // the values separator Header []interface{} SkipLines int Comment string LazyQuotes bool Limit int }
ReadInput provides the input for the Read function.
type WriteInput ¶
type WriteInput struct { Writer io.Writer // the underlying writer Separator rune // the values separator Header []interface{} KeySerializer stringify.Stringer ValueSerializer stringify.Stringer Object interface{} // the object to write ExpandHeader bool // dynamically expand header, requires caching output in memory Sorted bool // sort columns Reversed bool // if sorted, sort in reverse alphabetical order. Limit int }
WriteInput provides the input for the Write function.
type WriteTableInput ¶
type WriteTableInput struct { Writer io.Writer // the underlying writer Separator rune // the values separator Header []string // the table header Rows [][]string // the row of values to write to the underlying writer Sorted bool // sort the columns Reversed bool // if sorted, sort in reverse order }
WriteTableInput provides the input for the WriteTable function.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
func NewWriter ¶
func NewWriter(underlying io.Writer, separator rune, columns []interface{}, keySerializer stringify.Stringer, valueSerializer stringify.Stringer, sorted bool, reversed bool) *Writer
NewWriter returns a new Writer for writing objects to an underlying writer formatted as separated values. NewWriter is a streaming writer, so cannot dynamically expand the header. To dynamically expand the header, then use the Write function with ExpandHeader set to true.
func (*Writer) Close ¶ added in v0.0.9
Close closes the underlying writer, if it has a Close method.
func (*Writer) WriteHeader ¶
func (*Writer) WriteObject ¶
func (*Writer) WriteObjects ¶
Source Files ¶
- CreateHeaderAndKnownKeys.go
- CreateHeaderAndKnownKeysFromValue.go
- ErrInvalidFormat.go
- ExpandHeader.go
- ExpandHeaderWithWildcard.go
- FillRight.go
- FillRight_Test.go
- Flusher.go
- FormatToSeparator.go
- GetKeys.go
- GetKeysFromValue.go
- Iterator.go
- Read.go
- RemoveWildcard.go
- Row.go
- SortTable.go
- ToRow.go
- ToRowFromValue.go
- Write.go
- WriteTable.go
- Writer.go
- sv.go