csv

package module
v0.0.0-...-329a703 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2015 License: MIT Imports: 6 Imported by: 0

README

CSV

Introduction

This small package provides a CSV Encoder similar to json.Encoder or xml.Encoder of the standard library.

It is an early version and currently only handles slices of structs. So pull requests are welcomed to fix bugs or handle more use cases (slices or maps of string, etc.).

Documentation

http://godoc.org/github.com/SoCloz/csv

Download

go get github.com/SoCloz/csv

Example

package main

import (
	"github.com/SoCloz/csv"
)

func main() {
	v := []struct {
		Name string
		Age  int
	}{
		{Name: "Bob", Age: 42},
		{Name: "Joe", Age: 17},
	}
	err := csv.NewEncoder(os.Stdout).Encode(v)
	if err != nil {
		panic(err)
	}
	// Output:
	// Name,Age
	// Bob,42
	// Joe,17
}

Documentation

Overview

Package csv provides a CSV Encoder similar to json.Encoder or xml.Encoder.

Example
v := []struct {
	Name string
	Age  int
}{
	{Name: "Bob", Age: 42},
	{Name: "Joe", Age: 17},
}
err := NewEncoder(os.Stdout).Encode(v)
if err != nil {
	panic(err)
}
Output:

Name,Age
Bob,42
Joe,17

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Encoder

type Encoder struct {
	SkipHeader bool
	Writer     *csv.Writer
}

An Encoder writes CSV objects 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(v interface{}) error

Encode writes the CSV encoding of v to the stream.

Jump to

Keyboard shortcuts

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