{"id":17882133,"url":"https://github.com/nao1215/csv","last_synced_at":"2025-10-07T09:21:52.000Z","repository":{"id":239349594,"uuid":"799058421","full_name":"nao1215/csv","owner":"nao1215","description":"csv  - read csv with validation in golang","archived":false,"fork":false,"pushed_at":"2025-03-12T12:10:55.000Z","size":88,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-12T13:23:08.041Z","etag":null,"topics":["csv","golang","golang-library","validator"],"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/nao1215.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"nao1215"}},"created_at":"2024-05-11T04:26:45.000Z","updated_at":"2025-03-12T12:10:52.000Z","dependencies_parsed_at":"2024-05-16T03:35:35.696Z","dependency_job_id":"8e388bc0-efb9-432d-886a-671fde33e6c2","html_url":"https://github.com/nao1215/csv","commit_stats":null,"previous_names":["nao1215/csv"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nao1215%2Fcsv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nao1215%2Fcsv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nao1215%2Fcsv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nao1215%2Fcsv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nao1215","download_url":"https://codeload.github.com/nao1215/csv/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244207736,"owners_count":20416107,"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","golang","golang-library","validator"],"created_at":"2024-10-28T12:48:17.248Z","updated_at":"2025-10-07T09:21:46.936Z","avatar_url":"https://github.com/nao1215.png","language":"Go","funding_links":["https://github.com/sponsors/nao1215"],"categories":[],"sub_categories":[],"readme":"\u003c!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --\u003e\n[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-)\n\u003c!-- ALL-CONTRIBUTORS-BADGE:END --\u003e\n[![Go Reference](https://pkg.go.dev/badge/github.com/nao1215/csv.svg)](https://pkg.go.dev/github.com/nao1215/csv)\n[![MultiPlatformUnitTest](https://github.com/nao1215/csv/actions/workflows/multi_platform_ut.yml/badge.svg)](https://github.com/nao1215/csv/actions/workflows/multi_platform_ut.yml)\n[![reviewdog](https://github.com/nao1215/csv/actions/workflows/reviewdog.yml/badge.svg)](https://github.com/nao1215/csv/actions/workflows/reviewdog.yml)\n![Coverage](https://raw.githubusercontent.com/nao1215/octocovs-central-repo/main/badges/nao1215/csv/coverage.svg)\n\n## What is csv package?\n\nThe csv package is a library for performing validation when reading CSV or TSV files. Validation rules are specified using struct tags. The csv package read returns which columns of which rows do not adhere to the specified rules.\n  \nWe are implementing internationalization (i18n) for error messages. \n\n### Supported OS and Go versions\n\n- Linux\n- macOS\n- Windows\n- go version 1.23 or later\n\n### Supported languages\n\n- English\n- Japanese\n- Russian\n\nIf you want to add a new language, please create a pull request.\nRef. https://github.com/nao1215/csv/pull/8\n\n## Why need csv package?\n\nI was frustrated with error-filled CSV files written by non-engineers.\n\nI encountered a use case of \"importing one CSV file into multiple DB tables\". Unfortunately, I couldn't directly import the CSV file into the DB tables. So, I attempted to import the CSV file through a Go-based application.\n\nWhat frustrated me was not knowing where the errors in the CSV file were. Existing libraries didn't provide output like \"The value in the Mth column of the Nth row is incorrect\". I attempted to import multiple times and processed error messages one by one. Eventually, I started writing code to parse each column, which wasted a considerable amount of time.\n\nBased on the above experience, I decided to create a generic CSV validation tool.\n\n## How to use\n\nPlease attach the \"validate:\" tag to your structure and write the validation rules after it. It's crucial that the \"order of columns\" matches the \"order of field definitions\" in the structure. The csv package does not automatically adjust the order.\n\nWhen using csv.Decode, please pass a pointer to a slice of structures tagged with struct tags. The csv package will perform validation based on the struct tags and save the read results to the slice of structures if there are no errors. If there are errors, it will return them as []error.\n\n### Example: english error message\n```go\npackage main\n\nimport (\n\t\"bytes\"\n\t\"fmt\"\n\n\t\"github.com/nao1215/csv\"\n)\n\nfunc main() {\n\tinput := `id,name,age\n1,Gina,23\na,Yulia,25\n3,Den1s,30\n`\n\tbuf := bytes.NewBufferString(input)\n\tc, err := csv.NewCSV(buf)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\ttype person struct {\n\t\tID   int    `validate:\"numeric\"`\n\t\tName string `validate:\"alpha\"`\n\t\tAge  int    `validate:\"gt=24\"`\n\t}\n\tpeople := make([]person, 0)\n\n\terrs := c.Decode(\u0026people)\n\tif len(errs) != 0 {\n\t\tfor _, err := range errs {\n\t\t\tfmt.Println(err.Error())\n\t\t}\n\t}\n\n\t// Output:\n\t// line:2 column age: target is not greater than the threshold value: threshold=24, value=23\n\t// line:3 column id: target is not a numeric character: value=a\n\t// line:4 column name: target is not an alphabetic character: value=Den1s\n}\n```\n\n### Example: japanese error message\n\n```go\nfunc main() {\n\tinput := `id,name,age\n1,Gina,23\na,Yulia,25\n3,Den1s,30\n`\n\tbuf := bytes.NewBufferString(input)\n\tc, err := csv.NewCSV(buf, csv.WithJapaneseLanguage()) // Set Japanese language option\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\ttype person struct {\n\t\tID   int    `validate:\"numeric\"`\n\t\tName string `validate:\"alpha\"`\n\t\tAge  int    `validate:\"gt=24\"`\n\t}\n\tpeople := make([]person, 0)\n\n\terrs := c.Decode(\u0026people)\n\tif len(errs) != 0 {\n\t\tfor _, err := range errs {\n\t\t\tfmt.Println(err.Error())\n\t\t}\n\t}\n\n\t// Output:\n\t// line:2 column age: 値がしきい値より大きくありません: threshold=24, value=23\n\t// line:3 column id: 値が数字ではありません: value=a\n\t// line:4 column name: 値がアルファベット文字ではありません: value=Den1s\n}\n```\n\n### Struct tags\n\nYou set the validation rules following the \"validate:\" tag according to the rules in the table below. If you need to set multiple rules, please enumerate them separated by commas.\n\n#### Strings\n\n| Tag Name          | Description                                       |\n|-------------------|---------------------------------------------------|\n| alpha             | Check whether value is alphabetic or not           |\n| alphanumeric     | Check whether value is alphanumeric or not        |\n| ascii             | Check whether value is ASCII or not                |\n| boolean           | Check whether value is boolean or not.           |\n| contains          | Check whether value contains the specified substring \u003cbr\u003e e.g. `validate:\"contains=abc\"` |\n| containsany       | Check whether value contains any of the specified characters \u003cbr\u003e e.g. `validate:\"containsany=abc def\"` |\n| lowercase         | Check whether value is lowercase or not           |\n| numeric           | Check whether value is numeric or not              |\n| uppercase         | Check whether value is uppercase or not           |\n\n#### Format\n\n| Tag Name          | Description                                       |\n|-------------------|---------------------------------------------------|\n| email             | Check whether value is an email address or not     |\n\n#### Comparisons\n\n| Tag Name          | Description                                       |\n|-------------------|---------------------------------------------------|\n| eq                | Check whether value is equal to the specified value.\u003cbr\u003e e.g. `validate:\"eq=1\"` |\n| gt                | Check whether value is greater than the specified value \u003cbr\u003e e.g. `validate:\"gt=1\"` |\n| gte               | Check whether value is greater than or equal to the specified value \u003cbr\u003e e.g. `validate:\"gte=1\"` |\n| lt                | Check whether value is less than the specified value \u003cbr\u003e e.g. `validate:\"lt=1\"` |\n| lte               | Check whether value is less than or equal to the specified value \u003cbr\u003e e.g. `validate:\"lte=1\"` |\n| ne                | Check whether value is not equal to the specified value \u003cbr\u003e e.g. `validate:\"ne=1\"` |\n\n#### Other\n\n| Tag Name          | Description                                       |\n|-------------------|---------------------------------------------------|\n| len \t\t\t    | Check whether the length of the value is equal to the specified value \u003cbr\u003e e.g. `validate:\"len=10\"` |\n| max               | Check whether value is less than or equal to the specified value \u003cbr\u003e e.g. `validate:\"max=100\"` |\n| min               | Check whether value is greater than or equal to the specified value \u003cbr\u003e e.g. `validate:\"min=1\"` |\n| oneof             | Check whether value is included in the specified values \u003cbr\u003e e.g. `validate:\"oneof=male female prefer_not_to\"` |\n| required          | Check whether value is empty or not                |\n\n## License\n[MIT License](./LICENSE)\n\n## Contribution\n\nFirst off, thanks for taking the time to contribute! See [CONTRIBUTING.md](./CONTRIBUTING.md) for more information. Contributions are not only related to development. For example, GitHub Star motivates me to develop! Please feel free to contribute to this project.\n\n[![Star History Chart](https://api.star-history.com/svg?repos=nao1215/csv\u0026type=Date)](https://star-history.com/#nao1215/csv\u0026Date)\n\n### Special Thanks\n\nI was inspired by the following OSS. Thank you for your great work!\n- [go-playground/validator](https://github.com/go-playground/validator)\n- [shogo82148/go-header-csv](https://github.com/shogo82148/go-header-csv)\n\n### Contributors ✨\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://debimate.jp/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/22737008?v=4?s=75\" width=\"75px;\" alt=\"CHIKAMATSU Naohiro\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eCHIKAMATSU Naohiro\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/nao1215/csv/commits?author=nao1215\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n  \u003ctfoot\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\" size=\"13px\" colspan=\"7\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/all-contributors/all-contributors-cli/1b8533af435da9854653492b1327a23a4dbd0a10/assets/logo-small.svg\"\u003e\n          \u003ca href=\"https://all-contributors.js.org/docs/en/bot/usage\"\u003eAdd your contributions\u003c/a\u003e\n        \u003c/img\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tfoot\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-restore --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnao1215%2Fcsv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnao1215%2Fcsv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnao1215%2Fcsv/lists"}