CSValidator is a tool for validation of .csv files using JSON schema
go get -u github.com/markelrep/csvalidator
{
"columns":[
{
"name": "id",
"required": true
},
{
"name": "comment",
"required": false
}
]
}columns is array of objects with validation rules for each columns in .csv file
name of column, which should be the same as in .csv file otherwise validation will be failed. This field also supports regexp. Example
required true means that this column is required to exist in file, false that isn't required
package main
import "github.com/markelrep/csvalidator"
func main() {
validator, err := csvalidator.NewValidator(csvalidator.Config{
FilePath: "./path/to/csv/files",
FirstIsHeader: true,
SchemaPath: "./path/to/json/schema",
WorkerPoolSize: 0,
// If ErrFilePath is defined then all errors with be written to this file else to the std our
ErrFilePath "./path/to/dst/file/with/errors"
})
if err != nil {
// handle error
}
if err := validator.Validate(); err != nil {
// handle error
}
}