go-csv-tag: github.com/artonge/go-csv-tag Index | Files

package csvtag

import "github.com/artonge/go-csv-tag"

Index

Package Files

csvtag.go dump.go load.go

func DumpToFile Uses

func DumpToFile(slice interface{}, path string, options ...CsvOptions) error

DumpToFile - writes a slice content into a file specified by path. @param slice: An object typically of the form []struct, where the struct is using csv tag. @param path: The file path string of where you want the file to be created. @param options (optional): options for the csv parsing. @return an error if one occures.

func DumpToString Uses

func DumpToString(slice interface{}, options ...CsvOptions) (string, error)

DumpToString - writes a slice content into a string. @param slice: An object typically of the form []struct, where the struct is using csv tag. @param options (optional): options for the csv parsing. @return a string and an error if one occures.

func DumpToWriter Uses

func DumpToWriter(slice interface{}, writer io.Writer, options ...CsvOptions) error

DumpToWriter - writes a slice content into an io.Writer. @param slice: an object typically of the form []struct, where the struct is using csv tags. @param writer: the location of where you will write the slice content to. Example: File, Stdout, etc. @param options (optional): options for the csv parsing. @return an error if one occures.

func LoadFromPath Uses

func LoadFromPath(path string, destination interface{}, options ...CsvOptions) error

LoadFromPath - Load csv from a path and put it in a array of the destination's type using tags. Example:

tabOfMyStruct := []MyStruct{}
err  := Load(
			"my_csv_file.csv",
			&tabOfMyStruct,
			CsvOptions{
				Separator: ';',
				Header: []string{"header1", "header2", "header3"
			}
		})

@param path: the path of the csv file. @param destination: object where to store the result. @param options (optional): options for the csv parsing. @return an error if one occurs.

func LoadFromReader Uses

func LoadFromReader(file io.Reader, destination interface{}, options ...CsvOptions) error

LoadFromReader - Load csv from an io.Reader and put it in a array of the destination's type using tags. Example:

tabOfMyStruct := []MyStruct{}
err  := Load(
			myIoReader,
			&tabOfMyStruct,
			CsvOptions{
				Separator: ';',
				Header: []string{"header1", "header2", "header3"
			}
		})

@param file: the io.Reader. @param destination: object where to store the result. @param options (optional): options for the csv parsing. @return an error if one occurs.

func LoadFromString Uses

func LoadFromString(str string, destination interface{}, options ...CsvOptions) error

LoadFromString - Load csv from string and put it in a array of the destination's type using tags. Example:

tabOfMyStruct := []MyStruct{}
err  := Load(
			myString,
			&tabOfMyStruct,
			CsvOptions{
				Separator: ';',
				Header: []string{"header1", "header2", "header3"
			}
		})

@param str: the string. @param destination: object where to store the result. @param options (optional): options for the csv parsing. @return an error if one occurs.

type CsvOptions Uses

type CsvOptions struct {
    Separator rune
    Header    []string
}

CsvOptions - options when loading or dumping csv.

Package csvtag imports 9 packages (graph) and is imported by 1 packages. Updated 2019-11-25. Refresh now. Tools for package owners.