csvalidator

package module
v0.2.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2023 License: MIT Imports: 10 Imported by: 0

README

CSValidator

CSValidator is a tool for validation of .csv files using JSON schema

Quick Start

Install

go get -u github.com/markelrep/csvalidator

Schema
{
  "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

Usage
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
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator stores csv files which to be validated and validate rules

func NewValidator

func NewValidator(config config.Config) (Validator, error)

NewValidator creates a new Validator

func (*Validator) Validate

func (v *Validator) Validate() error

Validate checks files and expose errors. each file check runs concurrently errors return after all files are validated

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL