{"id":22967780,"url":"https://github.com/jabolopes/csvstruct","last_synced_at":"2025-10-25T01:04:43.505Z","repository":{"id":250768475,"uuid":"835401005","full_name":"jabolopes/csvstruct","owner":"jabolopes","description":"Import multiply-typed structured data from CSV to Go types","archived":false,"fork":false,"pushed_at":"2024-08-09T23:33:56.000Z","size":31,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-07T19:49:25.732Z","etag":null,"topics":["csv","ecs","entity-component-system","go","golang","golang-library","spreadsheet"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jabolopes.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":"2024-07-29T18:58:20.000Z","updated_at":"2024-08-09T23:33:59.000Z","dependencies_parsed_at":"2024-08-10T00:45:16.785Z","dependency_job_id":null,"html_url":"https://github.com/jabolopes/csvstruct","commit_stats":null,"previous_names":["jabolopes/csvstruct"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jabolopes%2Fcsvstruct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jabolopes%2Fcsvstruct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jabolopes%2Fcsvstruct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jabolopes%2Fcsvstruct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jabolopes","download_url":"https://codeload.github.com/jabolopes/csvstruct/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246758589,"owners_count":20828956,"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":["csv","ecs","entity-component-system","go","golang","golang-library","spreadsheet"],"created_at":"2024-12-14T21:14:43.165Z","updated_at":"2025-10-25T01:04:43.485Z","avatar_url":"https://github.com/jabolopes.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# csvstruct\n\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/jabolopes/go-ecs)](https://pkg.go.dev/github.com/jabolopes/csvstruct)\n\nImport multiply-typed structured data from CSV to Go types.\n\nImport spreadsheets:\n\n![screenshot](https://github.com/user-attachments/assets/62e920eb-d92f-4419-910f-384bbbd6f6c0)\n\nInto Go types:\n\n```go\ntype Info struct {\n  Name string\n  Class string\n}\n\ntype Attributes struct {\n  HP int\n  Damage int\n}\n\ntype Prefab struct {\n  Info *Info\n  Attributes *Attributes\n}\n```\n\nGet typed data:\n\n```go\nPrefab{Info{\"Alex\", \"Fighter\"}, Attributes{100, 10}}\nPrefab{Info{\"Mary\", \"Queen\"}, nil}\nPrefab{Info{\"Jayden\", \"Wizard\"}, Attributes{90, 20}}\n```\n\nWhen working with Google Sheets or Microsoft Excel, export data to CSV and\nimport it to your program using the csvstruct library.\n\n## Example\n\nLet's assume the following CSS file:\n\n```css\nInfo.Name,Info.Class,Attributes.HP,Attributes.Damage\nAlex,Fighter,100,10\nJayden,Wizard,90,20\nMary,Queen,,\n...\n```\n\nThe following program uses csvstruct library to import the data above:\n\n```go\ntype Info struct {\n    Name  string\n    Class string\n}\n\ntype Attributes struct {\n    HP     int\n    Damage int\n}\n\ntype Prefab struct {\n    Info       *Info\n    Attributes *Attributes\n}\n\nreader := csvstruct.NewReader[Prefab](csv.NewReader(strings.NewReader(testData)))\n\nvar prefab Prefab\nfor {\n    err := reader.Read(\u0026prefab)\n    if err == io.EOF {\n        break\n    }\n    if err != nil {\n        panic(err)\n    }\n\n    fmt.Printf(\"%v\\n\", prefab.Info)\n    fmt.Printf(\"%v\\n\", prefab.Attributes)\n}\n```\n\n## Format\n\nThe CSV data must have the following format:\n\n### Header\n\nThe first row of the CSV data is the header and it must be present.\n\nEach header column contains the name of a component followed by a period `.` and\nan optional field name, e.g., `MyComponent.MyField`.\n\nThe `MyComponent.MyField` must be valid, i.e., `MyComponent` must be a valid\nfield name of the type `T` passed to `NewReader`, and `MyField` must be a valid\nfield of `MyComponent`.\n\nIf a cell is not given, then it's field is default initialized according to the\ndefault initialization of Go. For example, pointers are default initialized to\n`nil` and value types are default initialized to `0`, empty structs, empty\narrays, etc.\n\nIt's not required to put in the CSV header all the fields of\n`MyComponent`. Rather, only the fields that should be imported by those CSV data\nare present.\n\n### Data rows\n\nThe rows that follow a CSV header are data rows.\n\nThe CSV data can contain 0 or more data rows.\n\nThe data rows must contain in each cell data that is compatible with\nthe type of the field specified in the CSV header.\n\nFor example, a field of type string can contain either an empty or\nnon-empty cell (without quotes) since that is compatible with the\nstring type.\n\nA field of type `Int` can either an empty or non-empty cell containing\na numerical value.\n\nEmpty cells default initialize fields according to Go semantics.\n\n### Multiple tables in the same CSV\n\nIt's possible to have multiple \"tables\" in the same CSV file. Tables are\nseparate by CSV header rows. The library caller must be able to determine when a\nnew CSV header is about to come up as the next row. In this case, the caller can\nuse `Reader.Clear` to start a new table of CSV data, followed by `Reader.Read`\nto parse the new table.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjabolopes%2Fcsvstruct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjabolopes%2Fcsvstruct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjabolopes%2Fcsvstruct/lists"}