{"id":13490150,"url":"https://github.com/gocarina/gocsv","last_synced_at":"2025-04-23T23:14:22.643Z","repository":{"id":16577209,"uuid":"19331272","full_name":"gocarina/gocsv","owner":"gocarina","description":"The GoCSV package aims to provide easy CSV serialization and deserialization to the golang programming language","archived":false,"fork":false,"pushed_at":"2024-05-20T20:11:08.000Z","size":301,"stargazers_count":2075,"open_issues_count":82,"forks_count":253,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-04-23T23:14:20.033Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gocarina.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-05-01T00:13:54.000Z","updated_at":"2025-04-22T16:45:10.000Z","dependencies_parsed_at":"2023-02-13T04:31:26.952Z","dependency_job_id":"40841533-50b1-4be3-a555-d55418959177","html_url":"https://github.com/gocarina/gocsv","commit_stats":{"total_commits":210,"total_committers":92,"mean_commits":2.282608695652174,"dds":0.9142857142857143,"last_synced_commit":"78e41c74b4b12494f15ca9d720e61e3de556619c"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gocarina%2Fgocsv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gocarina%2Fgocsv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gocarina%2Fgocsv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gocarina%2Fgocsv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gocarina","download_url":"https://codeload.github.com/gocarina/gocsv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250528879,"owners_count":21445518,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T19:00:41.650Z","updated_at":"2025-04-23T23:14:22.625Z","avatar_url":"https://github.com/gocarina.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"Go CSV\n=====\n\nThe GoCSV package aims to provide easy serialization and deserialization functions to use CSV in Golang\n\nAPI and techniques inspired from https://godoc.org/gopkg.in/mgo.v2\n\n[![GoDoc](https://godoc.org/github.com/gocarina/gocsv?status.png)](https://godoc.org/github.com/gocarina/gocsv)\n[![Build Status](https://travis-ci.org/gocarina/gocsv.svg?branch=master)](https://travis-ci.org/gocarina/gocsv)\n\nInstallation\n=====\n\n```go get -u github.com/gocarina/gocsv```\n\nFull example\n=====\n\nConsider the following CSV file\n\n```csv\n\nclient_id,client_name,client_age\n1,Jose,42\n2,Daniel,26\n3,Vincent,32\n\n```\n\nEasy binding in Go!\n---\n\n```go\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/gocarina/gocsv\"\n)\n\ntype NotUsed struct {\n\tName string\n}\n\ntype Client struct { // Our example struct, you can use \"-\" to ignore a field\n\tId            string `csv:\"client_id\"`\n\tName          string `csv:\"client_name\"`\n\tAge           string `csv:\"client_age\"`\n\tNotUsedString string `csv:\"-\"`\n\tNotUsedStruct NotUsed `csv:\"-\"` \n}\n\nfunc main() {\n\tclientsFile, err := os.OpenFile(\"clients.csv\", os.O_RDWR|os.O_CREATE, os.ModePerm)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer clientsFile.Close()\n\n\tclients := []*Client{}\n\n\tif err := gocsv.UnmarshalFile(clientsFile, \u0026clients); err != nil { // Load clients from file\n\t\tpanic(err)\n\t}\n\tfor _, client := range clients {\n\t\tfmt.Println(\"Hello\", client.Name)\n\t}\n\n\tif _, err := clientsFile.Seek(0, 0); err != nil { // Go to the start of the file\n\t\tpanic(err)\n\t}\n\n\tclients = append(clients, \u0026Client{Id: \"12\", Name: \"John\", Age: \"21\"}) // Add clients\n\tclients = append(clients, \u0026Client{Id: \"13\", Name: \"Fred\"})\n\tclients = append(clients, \u0026Client{Id: \"14\", Name: \"James\", Age: \"32\"})\n\tclients = append(clients, \u0026Client{Id: \"15\", Name: \"Danny\"})\n\tcsvContent, err := gocsv.MarshalString(\u0026clients) // Get all clients as CSV string\n\t//err = gocsv.MarshalFile(\u0026clients, clientsFile) // Use this to save the CSV back to the file\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(csvContent) // Display all clients as CSV string\n\n}\n\n```\n\nCustomizable Converters\n---\n\n```go\n\ntype DateTime struct {\n\ttime.Time\n}\n\n// Convert the internal date as CSV string\nfunc (date *DateTime) MarshalCSV() (string, error) {\n\treturn date.Time.Format(\"20060201\"), nil\n}\n\n// You could also use the standard Stringer interface \nfunc (date *DateTime) String() (string) {\n\treturn date.String() // Redundant, just for example\n}\n\n// Convert the CSV string as internal date\nfunc (date *DateTime) UnmarshalCSV(csv string) (err error) {\n\tdate.Time, err = time.Parse(\"20060201\", csv)\n\treturn err\n}\n\ntype Client struct { // Our example struct with a custom type (DateTime)\n\tId       string   `csv:\"id\"`\n\tName     string   `csv:\"name\"`\n\tEmployed DateTime `csv:\"employed\"`\n}\n\n```\n\nCustomizable CSV Reader / Writer\n---\n\n```go\n\nfunc main() {\n        ...\n\t\n        gocsv.SetCSVReader(func(in io.Reader) gocsv.CSVReader {\n            r := csv.NewReader(in)\n            r.Comma = '|'\n            return r // Allows use pipe as delimiter\n        })\t\n\t\n        ...\n\t\n        gocsv.SetCSVReader(func(in io.Reader) gocsv.CSVReader {\n            r := csv.NewReader(in)\n            r.LazyQuotes = true\n            r.Comma = '.'\n            return r // Allows use dot as delimiter and use quotes in CSV\n        })\n\t\n        ...\n\t\n        gocsv.SetCSVReader(func(in io.Reader) gocsv.CSVReader {\n            //return csv.NewReader(in)\n            return gocsv.LazyCSVReader(in) // Allows use of quotes in CSV\n        })\n\n        ...\n\n        gocsv.UnmarshalFile(file, \u0026clients)\n\n        ...\n\n        gocsv.SetCSVWriter(func(out io.Writer) *gocsv.SafeCSVWriter {\n            writer := csv.NewWriter(out)\n            writer.Comma = '|'\n            return gocsv.NewSafeCSVWriter(writer)\n        })\n\n        ...\n\n        gocsv.MarshalFile(\u0026clients, file)\n\n        ...\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgocarina%2Fgocsv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgocarina%2Fgocsv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgocarina%2Fgocsv/lists"}