{"id":20171930,"url":"https://github.com/harwoeck/magic","last_synced_at":"2026-06-20T06:31:04.326Z","repository":{"id":57633746,"uuid":"214154059","full_name":"harwoeck/magic","owner":"harwoeck","description":":carousel_horse: magic is an auto-parsing library and competitive coding helper package with batteries included. The library takes care of allocating and populating your memory.","archived":false,"fork":false,"pushed_at":"2020-05-02T09:53:03.000Z","size":42,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-13T09:04:18.869Z","etag":null,"topics":["auto-parsing","competitive-programming","competitive-programming-contests","go","golang","hacktoberfest","hacktoberfest2019","input-parsing","magic","not-for-production","parsing","reflect","reflection","reflection-magic"],"latest_commit_sha":null,"homepage":"https://harwoeck.com","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/harwoeck.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-10-10T10:31:14.000Z","updated_at":"2021-10-03T00:12:48.000Z","dependencies_parsed_at":"2022-08-31T18:31:07.103Z","dependency_job_id":null,"html_url":"https://github.com/harwoeck/magic","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/harwoeck/magic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harwoeck%2Fmagic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harwoeck%2Fmagic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harwoeck%2Fmagic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harwoeck%2Fmagic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/harwoeck","download_url":"https://codeload.github.com/harwoeck/magic/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harwoeck%2Fmagic/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34560265,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-20T02:00:06.407Z","response_time":98,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["auto-parsing","competitive-programming","competitive-programming-contests","go","golang","hacktoberfest","hacktoberfest2019","input-parsing","magic","not-for-production","parsing","reflect","reflection","reflection-magic"],"created_at":"2024-11-14T01:28:26.353Z","updated_at":"2026-06-20T06:31:04.294Z","avatar_url":"https://github.com/harwoeck.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# magic\n\n`magic` is an auto-parsing library and competitive coding helper package with batteries included. You just need to initialize it with a `SrcProvider` (e.g. a string, file, stream, etc.) and subsequently wish a type to auto-parse. The library takes care of allocating and populating your memory. The sequence of inputs is defined by the memory layout of the reading-type.\n\n**Under no circumstances should you use this package for production code. Use it only during competetive coding, when coding time matters and input parsing is trivial. I originally built this for the [Catalysts Coding Contest (codingcontest.org)](http://codingcontest.org)**\n\n[![GoDoc](https://godoc.org/github.com/harwoeck/magic?status.svg)](https://godoc.org/github.com/harwoeck/magic)\n[![Go Report Card](https://goreportcard.com/badge/github.com/harwoeck/magic)](https://goreportcard.com/report/github.com/harwoeck/magic)\n\n## Installation\n\nTo install `magic`, simly run:\n\n```bash\n$ go get -u github.com/harwoeck/magic\n```\n\n## Quick start\n\n1. Create a `SrcProvider`\n\n    ```go\n    src := bufio.NewScanner(strings.NewReader(\"INPUT\"))\n\n    f, _ := os.Open(\"/path/to/file.txt\")\n    src := bufio.NewScanner(f)\n    ```\n\n2. Create a new `Manager` instance\n\n    ```go\n    m := magic.NewManager(src)\n    ```\n\n3. `Read`, either primitive and complex types, from the manager\n\n    ```go\n    parsedBool := m.ReadBool()\n    parsedInt := m.ReadInt()\n    parsedFloat := m.ReadFloat32()\n    parsedString := m.ReadString()\n\n    parsedStructList := m.Read([]myStruct).([]myStruct)\n    ```\n\n### Complete example\n\nIn the following example a complex type (slice of structs) is read and auto-parsed. Within the main struct there are uncaped slices. In these situations `magic` will dynamically try to infer the size by reading an integer from the `SrcProvider` and incremting the cursor position accordingly.\n\n```go\ntype tx struct {\n    id        int64\n    authority string\n    from      []txpart\n    to        []txpart\n}\n\ntype txpart struct {\n    origin string\n    amount float64\n}\n\nfunc main() {\n    src := bufio.NewScanner(strings.NewReader(\n        // Image the strings below are single lines within an input-file\n        \"1 FINANCE_MINISTRY 1 YourBankAccount 100 1 MyBankAccount 100\\n\" +\n        \"2 FINANCE_MINISTRY_DE 2 YourBusinessAcount1 50 YourBusinessAcount2 150 1 MyBusinessAcount 200\\n\"\n    ))\n\n    m := magic.NewManager(src)\n\n    for _, item := range m.Read([]tx{}).([]tx) {\n        fmt.Printf(\"%d %s\\n\", item.id, item.authority)\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharwoeck%2Fmagic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fharwoeck%2Fmagic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharwoeck%2Fmagic/lists"}