csvparser

package module
v0.0.0-...-3f3248b Latest Latest
Warning

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

Go to latest
Published: May 29, 2015 License: GPL-2.0 Imports: 3 Imported by: 0

README

go-csvparser

Golang CSV parser into struct by tags

Package provides simple and noobie parsing of each csv line into struct.

Supports only strings because I didn't need others :)

See simple example in _example directory

Example:

package main

import (
  "os"

  "github.com/railsme/go-csvparser"
)

type User struct {
  Name  string `csv:"name"`
  Email string `csv:"email"`
  Phone string `csv:"phone"`
}

func main() {
  //Passing file name and empty struct to know data type
  err := csvparser.ParseEach("users.csv", User{}, func(v interface{}) {
    //Cast interface to our type
    user := v.(User)
    //Do something with data
    println("User:", user.Name)
    println("\tEmail:", user.Email)
    println("\tPhone:", user.Phone)
    println()
  })

  if err != nil {
    println("Oh, crap!", err.Error())
    os.Exit(1)
  }
}

Documentation

Overview

Package csvparser provides simple and noobie parsing of each csv line into struct Supports only strings because I didn't need others :) See simple example in _example directory

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseEach

func ParseEach(file string, v interface{}, callback func(result interface{})) error

ParseEach parses each line of csv file and passing interface{} to callback function

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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