Skip to content

x4b1/csvchecker

Repository files navigation

Csvchecker is a CSV structure and data validator written in pure Go

It can be used as a command or a package to use in your Go project.

Installation

go get github.com/xabi93/csvchecker

Usage

As mentioned this tool can be used as a package to use in your go project or as a command.

Package

checker := csvchecker.NewChecker(',', true)

checker.AddColum(
	csvchecker.NewColumn(
		1,
		csvchecker.NewStringValidation(
			true,
			csvchecker.NewRangeValidation(1, 5),
		),
	),
)

reader := strings.NewReader(`column1;colum2
value1;value2
;value3`)

errors := checker.Check(reader)

Command

The command usage is simple just:

csvchecker {configuration file path} {csv to validate}

Configuration file must have the folling structure:

{
    "separator": ";",
    "withHeader": true,
    "columns": [
        {
            "position": 1,
            "validation": {}
        }
    ]
}

string validator

{
    "type": "string",
    "allowEmpty": true,
    "range": {
        "min": 2,
        "max": 5
    }
}

number validator

{
    "type": "number",
    "allowEmpty": true,
    "range": {
        "min": 2,
        "max": 5
    }
}

regexp validator

{
    "type": "regexp",
    "regexp": "/+d/"
}

list values validator

{
    "type": "list",
    "allowEmpty": true,
    "list": [
        "test"
    ]
}

Contribute

Contributions are more than welcome

Releases

No releases published

Packages

No packages published

Languages