{"id":13397070,"url":"https://github.com/ahmedalhulaibi/flatfile","last_synced_at":"2026-01-14T13:36:46.346Z","repository":{"id":57507857,"uuid":"166619753","full_name":"ahmedalhulaibi/flatfile","owner":"ahmedalhulaibi","description":"A library to unmarshal structured data read from a flat-file (text file) into a struct using struct tags","archived":false,"fork":false,"pushed_at":"2020-12-01T18:46:13.000Z","size":88,"stargazers_count":16,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-07-31T18:19:00.574Z","etag":null,"topics":["converter","flat-file","go","golang","unmarshaller"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ahmedalhulaibi.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":"2019-01-20T03:38:49.000Z","updated_at":"2024-02-23T07:12:10.000Z","dependencies_parsed_at":"2022-09-26T17:50:47.287Z","dependency_job_id":null,"html_url":"https://github.com/ahmedalhulaibi/flatfile","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ahmedalhulaibi/flatfile","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmedalhulaibi%2Fflatfile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmedalhulaibi%2Fflatfile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmedalhulaibi%2Fflatfile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmedalhulaibi%2Fflatfile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahmedalhulaibi","download_url":"https://codeload.github.com/ahmedalhulaibi/flatfile/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmedalhulaibi%2Fflatfile/sbom","scorecard":{"id":172110,"data":{"date":"2025-08-11","repo":{"name":"github.com/ahmedalhulaibi/flatfile","commit":"ee3c85f29d00d2ed31f64b92a035455f32acea9a"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/21 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Mozilla Public License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 11 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-16T16:51:08.317Z","repository_id":57507857,"created_at":"2025-08-16T16:51:08.317Z","updated_at":"2025-08-16T16:51:08.317Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28421356,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T13:30:50.153Z","status":"ssl_error","status_checked_at":"2026-01-14T13:29:08.907Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":["converter","flat-file","go","golang","unmarshaller"],"created_at":"2024-07-30T18:01:10.473Z","updated_at":"2026-01-14T13:36:46.327Z","avatar_url":"https://github.com/ahmedalhulaibi.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# flatfile\n\n[![Pipeline](https://gitlab.com/ahmedalhulaibi/flatfile/badges/master/pipeline.svg)](https://gitlab.com/ahmedalhulaibi/flatfile/pipelines)[![codecov](https://codecov.io/gl/ahmedalhulaibi/flatfile/branch/master/graph/badge.svg)](https://codecov.io/gl/ahmedalhulaibi/flatfile)\n\n\n\nThis package provides a utility to read a fixed-width record from a [flat-file database](https://en.wikipedia.org/wiki/Flat-file_database) or a text file. The intent is to eliminate boilerplate code for reading data from a flat file and mapping it to the fields in a struct.\n\nThis package allows you to define your record layout mapping using struct tags.\n\nThis packge provides a method `Unmarshal` which will convert a record (slice of bytes) into a struct.\n\n# Usage\n\n## Download\n\nUse your favourite dependency tool to pull the code. dep, go mod, etc.\n\n`go get github.com/ahmedalhulaibi/flatfile`\n\n## Examples\n\nPlease refer to the [examples](https://github.com/ahmedalhulaibi/flatfile/tree/master/example) folder in repo for all examples.\n\nLet's say I have a text file `customers.txt` which contains customer data. There are 2 records:\n\n```\nAMY1900-01-01019123 FAKE STREETCA\nBOB1800-01-01037456 OLD STREET US\n```\nThe file layout is:\n```\nColumns  1, Length  3   = Customer Name\nColumns  4, Length 10   = Customer Join/Open Date\nColumns 14, Length  3   = Customer Age\nColumns 17, Length 15   = Customer Street Address\nColumns 32, Length  2   = Customer Country\n```\n\n\nEach field in a struct can be mapped to a single field in a record using a struct tag.\n\nStruct tags are in the form `flatfile:\"col,len\"` or for a slice field `flatfile:\"col,len,occurrences\"`.\n\nI can directly translate these to fields in a struct:\n\n```go\ntype CustomerRecord struct {\n    //flatfile is one indexed, column starts at 1\n    Name        string `flatfile:\"1,3\"`\n    OpenDate    string `flatfile:\"4,10\"`\n    Age         uint   `flatfile:\"14,3\"`\n    Address     string `flatfile:\"17,15\"`\n    CountryCode string `flatfile:\"32,2\"`\n}\n\n```\n\nOnce your layout is defined we can read a line from a file and unmarshal the data:\n\n```go\ntype CustomerRecord struct {\n\t//flatfile is one indexed, column starts at 1\n\tName        string `flatfile:\"1,3\"`\n\tOpenDate    string `flatfile:\"4,10\"`\n\tAge         uint   `flatfile:\"14,3\"`\n\tAddress     string `flatfile:\"17,15\"`\n\tCountryCode string `flatfile:\"32,2\"`\n}\n\nfunc main() {\n\tfile, err := os.Open(\"customers.txt\")\n\tcheckError(err)\n\tdefer file.Close()\n\n\treader := bufio.NewReader(file)\n\n\teof := false\n\tfor !eof {\n\t\tdata := readLine(reader)\n\t\tif data == nil {\n\t\t\teof = true\n\t\t} else {\n\t\t\tfileRecord := \u0026CustomerRecord{}\n            //unmarhsal text data to struct\n\t\t\terr := flatfile.Unmarshal(data, fileRecord, 0, 0)\n\t\t\tfmt.Printf(\"%v\\n\", fileRecord)\n\t\t\tcheckError(err)\n\t\t}\n\t}\n\tcheckError(err)\n}\n\nfunc readLine(reader *bufio.Reader) []byte {\n\tstr, _, err := reader.ReadLine()\n\tif err == io.EOF {\n\t\treturn nil\n\t}\n\n\treturn str\n}\n\nfunc checkError(err error) {\n\tif err != nil {\n\t\tpanic(err)\n\t}\n}\n```\n\n\n\n\n# Features\n\n## Data type support:\n- [x] bool\n- [x] string\n- [x] int\n- [x] int8\n- [x] int16\n- [x] int32\n- [x] int64\n- [x] uint\n- [x] uint8\n- [x] uint16\n- [x] uint32\n- [x] uint64\n- [x] float32\n- [x] float64\n- [x] rune\n- [x] byte\n- [x] Slice\n- [x] Array\n- [x] Nested struct\n- [x] Nested pointer (to any support type including struct)\n\n- [x] Slice, Array support AKA Emulate [COBOL occurs clause](https://www.ibm.com/support/knowledgecenter/en/SS6SG3_4.2.0/com.ibm.entcobol.doc_4.2/PGandLR/tasks/tptbl03.htm)\n\n- [x] Offset feature to support reading long lines of data. [Example](https://github.com/ahmedalhulaibi/flatfile/tree/master/example/bufferedReadFile)\n\n- [x] Byte and Rune support using type override. \n\n    These are aliases for uint8 and int32 respectively. These require an override option to be supplied.\n- [x] Flat File abstraction\n- [x] Support for conditional unmarshal \n    \n    if field(col,len) == \"text\" do unmarshal else skip. \n\tThis is done by supplying the `condition` option. The syntax is a bit funky:\n\n\t`col-len-VALUE` e.g. `1-10-TENLETTERS` This means the unmarshal will only occur if the data from column 1, length 10 is equals to TENLETTERS.\n    \n    This is useful for flat files where there are multiple record layouts within the same file.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmedalhulaibi%2Fflatfile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahmedalhulaibi%2Fflatfile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmedalhulaibi%2Fflatfile/lists"}