Documentation ¶
Overview ¶
Package xsv aims to provide easy CSV serialization and deserialization to the golang programming language
Index ¶
- Variables
- func CSVToMap(in io.Reader) (map[string]string, error)
- func UnmarshalCSVToMap(r *csv.Reader, out interface{}) error
- type ErrorHandler
- type NoMarshalFuncError
- type NoUnmarshalFuncError
- type Normalizer
- type TypeMarshaller
- type TypeUnmarshalCSVWithFields
- type TypeUnmarshaller
- type XsvRead
- type XsvReader
- func (r *XsvReader[T]) Lazy() *XsvReader[T]
- func (r *XsvReader[T]) ReadEach(c chan T) error
- func (r *XsvReader[T]) ReadEachWithoutHeaders(c chan T) error
- func (r *XsvReader[T]) ReadTo(out *[]T) error
- func (r *XsvReader[T]) ReadToCallback(f func(s T) error) error
- func (r *XsvReader[T]) ReadToWithoutHeaders(out *[]T) error
- func (r *XsvReader[T]) ToChanMaps(c chan<- map[string]string) error
- func (r *XsvReader[T]) ToMap() ([]map[string]string, error)
- type XsvWrite
- type XsvWriter
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmptyCSVFile = errors.New("empty csv file given") ErrNoStructTags = errors.New("no csv struct tags found") )
var (
ErrChannelIsClosed = errors.New("channel is closed")
)
Functions ¶
func UnmarshalCSVToMap ¶
UnmarshalCSVToMap parses a CSV of 2 columns into a map.
Types ¶
type ErrorHandler ¶
type ErrorHandler func(*csv.ParseError) bool
type NoMarshalFuncError ¶
type NoMarshalFuncError struct {
// contains filtered or unexported fields
}
NoMarshalFuncError is the custom error type to be raised in case there is no marshal function defined on type
func (NoMarshalFuncError) Error ¶
func (e NoMarshalFuncError) Error() string
type NoUnmarshalFuncError ¶
type NoUnmarshalFuncError struct {
// contains filtered or unexported fields
}
NoUnmarshalFuncError is the custom error type to be raised in case there is no unmarshal function defined on type
func (NoUnmarshalFuncError) Error ¶
func (e NoUnmarshalFuncError) Error() string
type Normalizer ¶
Normalizer is a function that takes and returns a string. It is applied to struct and header field values before they are compared. It can be used to alter names for comparison. For instance, you could allow case insensitive matching or convert '-' to '_'.
type TypeMarshaller ¶
TypeMarshaller is implemented by any value that has a MarshalCSV method This converter is used to convert the value to it string representation
type TypeUnmarshalCSVWithFields ¶
TypeUnmarshalCSVWithFields can be implemented on whole structs to allow for whole structures to customized internal vs one off fields
type TypeUnmarshaller ¶
TypeUnmarshaller is implemented by any value that has an UnmarshalCSV method This converter is used to convert a string to your value representation of that string
type XsvRead ¶
type XsvRead[T any] struct { TagName string //key in the struct field's tag to scan TagSeparator string //separator string for multiple csv tags in struct fields FailIfUnmatchedStructTags bool // indicates whether it is considered an error when there is an unmatched struct tag. FailIfDoubleHeaderNames bool // indicates whether it is considered an error when a header name is repeated in the csv header. ShouldAlignDuplicateHeadersWithStructFieldOrder bool // indicates whether we should align duplicate CSV headers per their alignment in the struct definition. OnRecord func(T) T // callback function to be called on each record NameNormalizer Normalizer ErrorHandler ErrorHandler }
XsvRead manages configuration values related to the csv read process.
func NewXsvRead ¶
NewXsvRead creates a new XsvRead struct with default configuration values
func (*XsvRead[T]) SetByteReader ¶
func (*XsvRead[T]) SetFileReader ¶
func (*XsvRead[T]) SetStringReader ¶
type XsvReader ¶
func NewXsvReader ¶
func (*XsvReader[T]) ReadEachWithoutHeaders ¶
func (*XsvReader[T]) ReadToCallback ¶
func (*XsvReader[T]) ReadToWithoutHeaders ¶
func (*XsvReader[T]) ToChanMaps ¶
type XsvWrite ¶
type XsvWrite[T any] struct { TagName string //key in the struct field's tag to scan TagSeparator string //separator string for multiple csv tags in struct fields OmitHeaders bool SelectedColumns []string // slice of field names to output SortOrder []int // column sort order HeaderModifier map[string]string // map to dynamically change headers OnRecord func(T) T // callback function to be called on each record // contains filtered or unexported fields }
XsvWrite manages configuration values related to the csv write process.
func NewXsvWrite ¶
NewXsvWrite creates a new XsvWrite struct with default configuration values