tsv

package module
Version: v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2019 License: MIT Imports: 6 Imported by: 0

README

TSV parser for Go

Build Status Coverage Status License

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

go get github.com/dogenzaka/tsv

Quickstart

tsv inserts data into struct by fields order.


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

type TestRow struct {
  Name   string // 0
  Age    int    // 1
  Gender string // 2
  Active bool   // 3
}

func main() {

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

  data := TestRow{}
  parser, _ := NewParser(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 `tsv:"name"`
  Age    int    `tsv:"age"`
  Gender string `tsv:"gender"`
  Active bool   `tsv:"bool"`
}

Supported field types

Currently this library supports limited fields

  • int
  • string
  • bool

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parser

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

Parser has information for parser

func NewParser

func NewParser(reader io.Reader, data interface{}) (*Parser, error)

NewStructModeParser creates new TSV parser with given io.Reader as struct mode

func NewParserWithoutHeader

func NewParserWithoutHeader(reader io.Reader, data interface{}) *Parser

NewParserWithoutHeader creates new TSV parser with given io.Reader

func (*Parser) Next

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

Next puts reader forward by a line

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL