csvparser

package module
v0.0.0-...-f8f3095 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

README

csvparser

The csvparser is a library to parse cvs file. It can marshal slice of struct to csv and vice-versa. It also has encoder and decoder.

Marshal
package main

import (
	"fmt"

	"github.com/Prithvipal/csvparser"
)

type Book struct {
	ID     int     `csv:"id"`
	Title  string  `csv:"book_title"`
	Price  float32 `csv:"price"`
	Author string  `csv:"name_of_author"`
}

func main() {
	books := make([]Book, 0)
	book1 := Book{ID: 101, Title: "Let us C", Price: 120.45, Author: "Prithvi"}
	books = append(books, book1)
	book2 := Book{ID: 102, Title: "Let us Go", Price: 490.95, Author: "Parthiv"}
	books = append(books, book2)
	data := csvparser.Marshal(books)
	fmt.Println(data)
}

Output

[[id book_title price name_of_author] 
[101 Let us C 1.2044999694824219E+02 Prithvi] 
[102 Let us Go 4.9095001220703125E+02 Parthiv]]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFieldNameTypeAndValue

func GetFieldNameTypeAndValue(i interface{})

GetFieldNameTypeAndValue ...

func Marshal

func Marshal(i interface{}) [][]string

Marshal ...

Types

type Decoder

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

An Decoder reads cvs values to an input stream.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a new decoder that reader from r.

type Encoder

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

An Encoder writes cvs values to an output stream.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns a new encoder that writes to w.

func (*Encoder) Encode

func (e *Encoder) Encode(i interface{})

Encode method writes cvs encoding

Jump to

Keyboard shortcuts

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