MCPcopy Index your code
hub / github.com/artonge/go-csv-tag

github.com/artonge/go-csv-tag @v2.6.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.6.0 ↗ · + Follow
49 symbols 129 edges 6 files 12 documented · 24%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

go-csv-tag

Read csv file from Go using tags

godoc for artonge/go-csv-tag

Go goreportcard for artonge/go-csv-tag

PRs Welcome

The project is in maintenance mode.

It is kept compatible with changes in the Go ecosystem but no new features will be developed. PR could be accepted.

Install

go get github.com/artonge/go-csv-tag/v2

Example

Load

The csv file:

name, ID, number
name1, 1, 1.2
name2, 2, 2.3
name3, 3, 3.4

Your Go code:

type Demo struct {                                // A structure with tags
    Name string  `csv:"name"`
    ID   int     `csv:"ID"`
    Num  float64 `csv:"number"`
}

tab := []Demo{}                                   // Create the slice where to put the content
err  := csvtag.LoadFromPath(
    "file.csv",                                   // Path of the csv file
    &tab,                                         // A pointer to the create slice
    csvtag.CsvOptions{                            // Load your csv with optional options
        Separator: ';',                           // changes the values separator, default to ','
        Header: []string{"name", "ID", "number"}, // specify custom headers
        TagKey: "csv",                            // specify a custom tag key, default to 'csv'
})

You can also load the data from an io.Reader with:

csvtag.LoadFromReader(youReader, &tab)

Or from a string with:

csvtag.LoadFromString(yourString, &tab)

Dump

Your Go code:

type Demo struct {                         // A structure with tags
    Name string  `csv:"name"`
    ID   int     `csv:"ID"`
    Num  float64 `csv:"number"`
}

tab := []Demo{                             // Create the slice where to put the content
    Demo{
        Name: "some name",
        ID: 1,
        Num: 42.5,
    },
}

err := csvtag.DumpToFile(tab, "csv_file_name.csv")

You can also dump the data into an io.Writer with:

err := csvtag.DumpToWriter(tab, yourIOWriter)

Or dump to a string with:

str, err := csvtag.DumpToString(tab)

The csv file written:

name,ID,number
some name,1,42.5

Core symbols most depended-on inside this repo

LoadFromPath
called by 16
load.go
DumpToWriter
called by 11
dump.go
LoadFromReader
called by 2
load.go
LoadFromString
called by 2
load.go
DumpToFile
called by 2
dump.go
DumpToString
called by 2
dump.go
readFile
called by 1
load.go
skipBOM
called by 1
load.go

Shape

Function 42
Struct 7

Languages

Go100%

Modules by API surface

load_test.go24 symbols
dump_test.go12 symbols
load.go7 symbols
dump.go3 symbols
csvtag_test.go2 symbols
csvtag.go1 symbols

For agents

$ claude mcp add go-csv-tag \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page