{"id":45316368,"url":"https://github.com/vchezganov/gocsv","last_synced_at":"2026-02-21T07:51:44.868Z","repository":{"id":37859038,"uuid":"461509692","full_name":"vchezganov/gocsv","owner":"vchezganov","description":"Simple CSV unmarshaller for Go structs","archived":false,"fork":false,"pushed_at":"2025-08-04T14:59:54.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-04T18:33:55.341Z","etag":null,"topics":["csv","go","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vchezganov.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}},"created_at":"2022-02-20T14:17:54.000Z","updated_at":"2022-06-15T12:29:53.000Z","dependencies_parsed_at":"2022-08-18T04:50:51.028Z","dependency_job_id":null,"html_url":"https://github.com/vchezganov/gocsv","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/vchezganov/gocsv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vchezganov%2Fgocsv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vchezganov%2Fgocsv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vchezganov%2Fgocsv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vchezganov%2Fgocsv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vchezganov","download_url":"https://codeload.github.com/vchezganov/gocsv/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vchezganov%2Fgocsv/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29676854,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T06:23:40.028Z","status":"ssl_error","status_checked_at":"2026-02-21T06:23:39.222Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["csv","go","golang"],"created_at":"2026-02-21T07:51:44.789Z","updated_at":"2026-02-21T07:51:44.861Z","avatar_url":"https://github.com/vchezganov.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## gocsv\nGo package for parsing CSV records into structs. Currently, it supports only\nthe following types and its references:\n- `int`, `int8`, `int16`, `int32`, `int64`\n- `uint`, `uint8`, `uint16`, `uint32`, `uint64`\n- `float32`, `float64`\n- `string`\n\nIn addition, you may provide own function to be used for parsing values. The function should accept `string` parameter and\nreturn `error` if there are any errors when parsing.\n\n## Examples\n\nCSV records could be iterated using `Next()` method that return the model or an error if any:\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"strings\"\n\n\t\"github.com/vchezganov/gocsv\"\n)\n\ntype Person struct {\n\tName string `csv:\"name\"`\n\tAge  uint   `csv:\"age\"`\n\tID   string `csv:\"pass,ParseID\"`\n}\n\nfunc (p *Person) ParseID(value string) error {\n\tp.ID = fmt.Sprintf(\"ABC-%s\", value)\n\treturn nil\n}\n\nfunc main() {\n\tstringReader := strings.NewReader(\"age,pass,name\\n32,12345,Vitaly\\n45,54321,Alexey\")\n\n\treader, err := gocsv.NewReader[Person](stringReader)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfor {\n\t\tmodel, err := reader.Next()\n\t\tif err == io.EOF {\n\t\t\tbreak\n\t\t} else if err != nil {\n\t\t\tcontinue\n\t\t}\n\n\t\tfmt.Printf(\"Person: %v\\n\", model)\n\t}\n}\n```\n\nStarting from Go 1.23 the cycle could be rewritten using simple `for` loop:\n```go\nfor model, err := reader.Iter() {\n\tif err != nil {\n\t\t\tcontinue\n\t}\n\t\n\tfmt.Printf(\"Person: %v\\n\", model)\n} \n```\n\n`csv.Reader` is accessible through `CSVReader` field for specific CSV parsing options:\n```go\nreader, err := gocsv.NewReader[Person](stringReader)\nif err != nil {\n    panic(err)\n}\n\nreader.CSVReader.Comma = '#'\n```\n\nYou may use `Marshaller` directly for complex cases:\n```go\npackage main\n\nimport (\n\t\"encoding/csv\"\n\t\"errors\"\n\t\"fmt\"\n\t\"strconv\"\n\t\"strings\"\n\n\t\"github.com/vchezganov/gocsv\"\n)\n\ntype Person struct {\n\tName     string `csv:\"name\"`\n\tAge      int    `csv:\"age\"`\n\tLocation string `csv:\"city\"`\n\tID       int    `csv:\"passport,ParseID\"`\n}\n\nfunc (p *Person) ParseID(value string) error {\n\ts, err := strconv.Atoi(value)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif 10000 \u003c= s \u0026\u0026 s \u003c= 99999 {\n\t\tp.ID = s\n\t\treturn nil\n\t}\n\n\treturn errors.New(\"ID is not valid\")\n}\n\nfunc main() {\n\ts := strings.NewReader(\"name,age,city,passport\\nVitaly,25,Bonn,10000\")\n\tcsvReader := csv.NewReader(s)\n\theaders, err := csvReader.Read()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tmarshaller, err := gocsv.NewMarshaller(headers)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tmodel := new(Person)\n\trecords, err := csvReader.Read()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\terr = marshaller.Unmarshal(records, model)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Printf(\"Person: %v\\n\", *model)\n}\n```\n\n\n## Next steps\n- Support composition\n```go\ntype A struct {\n\tID        int    `csv:\"id\"`\n\tTimestamp string `csv:\"timestamp\"`\n}\n\n// id, timestamp, name\ntype B struct {\n\t*A\n\tName int `csv:\"name\"`\n}\n\n// prefix_id, prefix_timestamp, name\ntype C struct {\n\tBase *A  `csv:\"prefix\"`\n\tName int `csv:\"name\"`\n}\n```\n- Parsing function to accept not only `string` but `int`, `float`, etc.\n- Converting structs into CSV dictionary, slice or string","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvchezganov%2Fgocsv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvchezganov%2Fgocsv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvchezganov%2Fgocsv/lists"}