dsv

package module
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2021 License: MIT Imports: 7 Imported by: 0

README

DSV parser for Go

License

DSV is delimiter-separated values parser for GO. It will parse lines and insert data into any type of struct. DSV supports both simple structs and structs with tagging.

go get github.com/angu1ss/dsv

Quickstart

DSV inserts data into struct by fields order.

import (
    "fmt"
    "os"
    "testing"
    )

type TestRow struct {
  Name   string
  Age    int
  Gender string
  Active bool
}

func main() {

  file, _ := os.Open("example.tsv")
  defer file.Close()

  data := TestRow{}
  parser, _ := NewTsvParser(file, &data)

  for {
    eof, err := parser.Next()
    if eof {
      return
    }
    if err != nil {
      panic(err)
    }
    fmt.Println(data)
  }

}

You can define tags to struct fields to map values

type TestRow struct {
  Name   string `dsv:"name"`
  Age    int    `dsv:"age"`
  Gender string `dsv:"gender"`
  Active bool   `dsv:"bool"`
}

Supported field types

Currently, library supports limited fields:

  • string
  • bool
  • int, base 10
  • int8, base 10
  • int16, base 10
  • int32, base 10
  • int64, base 10
  • unit, base 10
  • unit8, base 10
  • unit16, base 10
  • unit32, base 10
  • unit64, base 10
  • float32, delimiter is point, comma will be ignored
  • float64, delimiter is point, comma will be ignored
  • complex64
  • complex128

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Delimiters = map[string]rune{
	"tsv": '\t',
	"csv": ',',
}

Delimiters contains a map like "extension": "delimiter"

Functions

This section is empty.

Types

type Parser

type Parser struct {
	Headers []string
	Reader  *csv.Reader
	Data    interface{}
	// contains filtered or unexported fields
}

Parser has information for parser

func NewCsvParser

func NewCsvParser(reader io.Reader, lazyQuotes bool, data interface{}) (*Parser, error)

NewCsvParser creates new CSV parser with given io.Reader

func NewCsvParserWithoutHeader

func NewCsvParserWithoutHeader(reader io.Reader, lazyQuotes bool, data interface{}) (*Parser, error)

NewCsvParserWithoutHeader creates new CSV parser without header with given io.Reader

func NewParser

func NewParser(reader io.Reader, lazyQuotes bool, data interface{}, t string) (p *Parser, err error)

NewParser creates new DSV parser with given io.Reader and delimiter type

func NewParserWithoutHeader

func NewParserWithoutHeader(reader io.Reader, lazyQuotes bool, data interface{}, t string) (p *Parser, err error)

NewParserWithoutHeader creates new DSV parser with given io.Reader and delimiter type

func NewTsvParser

func NewTsvParser(reader io.Reader, lazyQuotes bool, data interface{}) (*Parser, error)

NewTsvParser creates new TSV parser with given io.Reader

func NewTsvParserWithoutHeader

func NewTsvParserWithoutHeader(reader io.Reader, lazyQuotes bool, data interface{}) (*Parser, error)

NewTsvParserWithoutHeader creates new TSV parser without header with given io.Reader

func (*Parser) Next

func (p *Parser) Next() (eof bool, err error)

Next puts reader forward by a line

Jump to

Keyboard shortcuts

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