Documentation
¶
Overview ¶
Package csv returns which columns have syntax errors on a per-line basis when reading CSV. It also has the capability to convert the character encoding to UTF-8 if the CSV character encoding is not UTF-8.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrStructSlicePointer is returned when the value is not a pointer to a struct slice. ErrStructSlicePointer = errors.New("value is not a pointer to a struct slice") // ErrInvalidBoolean is returned when the target is not a boolean. ErrInvalidBoolean = errors.New("target is not a boolean") // ErrInvalidAlphabet is returned when the target is not an alphabetic character. ErrInvalidAlphabet = errors.New("target is not an alphabetic character") // ErrInvalidNumeric is returned when the target is not a numeric character. ErrInvalidNumeric = errors.New("target is not a numeric character") // ErrInvalidAlphanumeric is returned when the target is not an alphanumeric character. ErrInvalidAlphanumeric = errors.New("target is not an alphanumeric character") // ErrRequired is returned when the target is required but is empty. ErrRequired = errors.New("target is required but is empty") // ErrEqual is returned when the target is not equal to the value. ErrEqual = errors.New("target is not equal to the threshold value") // ErrInvalidThreshold is returned when the target is not greater than the value. ErrInvalidThreshold = errors.New("threshold value is invalid") // ErrInvalidThresholdFormat is returned when the threshold value is not an integer. ErrInvalidThresholdFormat = errors.New("threshold format is invalid") // ErrNotEqual is returned when the target is equal to the value. ErrNotEqual = errors.New("target is equal to threshold the value") // ErrGreaterThan is returned when the target is not greater than the value. ErrGreaterThan = errors.New("target is not greater than the threshold value") // ErrGreaterThanEqual is returned when the target is not greater than or equal to the value. ErrGreaterThanEqual = errors.New("target is not greater than or equal to the threshold value") // ErrLessThan is returned when the target is not less than the value. ErrLessThan = errors.New("target is not less than the threshold value") // ErrLessThanEqual is returned when the target is not less than or equal to the value. ErrLessThanEqual = errors.New("target is not less than or equal to the threshold value") )
Functions ¶
This section is empty.
Types ¶
type CSV ¶
type CSV struct {
// contains filtered or unexported fields
}
CSV is a struct that implements CSV Reader and Writer.
Example ¶
package main import ( "bytes" "fmt" "github.com/nao1215/csv" ) func main() { input := `id,name,age 1,Gina,23 a,Yulia,25 3,Den1s,30 ` buf := bytes.NewBufferString(input) c, err := csv.NewCSV(buf) if err != nil { panic(err) } type person struct { ID int `validate:"numeric"` Name string `validate:"alpha"` Age int `validate:"gt=24"` } people := make([]person, 0) errs := c.Decode(&people) if len(errs) != 0 { for _, err := range errs { fmt.Println(err.Error()) } } }
Output: line:2 column age: target is not greater than the threshold value: threshold=24.000000, value=23.000000 line:3 column id: target is not a numeric character: value=a line:4 column name: target is not an alphabetic character: value=Den1s
type Option ¶
Option is a function that sets a configuration option for CSV struct.
func WithHeaderless ¶
func WithHeaderless() Option
WithHeaderless is an Option that sets the headerless flag to true.
func WithTabDelimiter ¶
func WithTabDelimiter() Option
WithTabDelimiter is an Option that sets the delimiter to a tab character.
Click to show internal directories.
Click to hide internal directories.