{"id":13563584,"url":"https://github.com/guregu/into","last_synced_at":"2025-07-13T02:09:23.604Z","repository":{"id":206463327,"uuid":"716846824","full_name":"guregu/into","owner":"guregu","description":"coercion convenience for Go","archived":false,"fork":false,"pushed_at":"2023-11-11T19:50:07.000Z","size":20,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-28T05:09:51.163Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/guregu.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},"funding":{"github":"guregu"}},"created_at":"2023-11-10T01:59:16.000Z","updated_at":"2023-11-10T08:34:26.000Z","dependencies_parsed_at":"2023-11-10T12:49:30.811Z","dependency_job_id":"46a05714-7373-45e0-ae46-4e42238ace8e","html_url":"https://github.com/guregu/into","commit_stats":null,"previous_names":["guregu/into"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guregu%2Finto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guregu%2Finto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guregu%2Finto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guregu%2Finto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guregu","download_url":"https://codeload.github.com/guregu/into/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245044493,"owners_count":20551898,"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":[],"created_at":"2024-08-01T13:01:21.043Z","updated_at":"2025-03-23T01:43:22.241Z","avatar_url":"https://github.com/guregu.png","language":"Go","funding_links":["https://github.com/sponsors/guregu"],"categories":["Go"],"sub_categories":[],"readme":"# into [![GoDoc](https://godoc.org/github.com/guregu/into?status.svg)](https://godoc.org/github.com/guregu/into)\n\n**into** provides convenience functions for coercing dynamic values to concrete values.\n\nInlcudes:\n- `into.String`, `into.Int`, `into.Uint`, `into.Float` for coercing `any` to their respective types\n- `into.CanString`, `into.CanInt`, `into.CanUint`, `into.CanFloat` for testing coercibility\n- `into.Try` and `into.Maybe` for catching panics and coercing them to `error`\n\n### Motivation\n\nThis library is an experiment that might be useful if you have to deal with `map[string]any`, writing data mapper libraries, etc.\nIt's not intended to replace `strconv`; if you know your concrete types ahead of time just use the standard library.\n\nThe panicking nature of the API is an idea borrowed from everyone's favorite, the standard library `reflect` package.\n\n## Example\n\n```go\na := into.Int(42) // 42\nb := into.Int(\"42\", into.WithConvertString) // 42\nc := into.Int(nil, into.WithFallback(1337)) // 1337\n\nvar ptr *int        // nil\nd := into.Int(ptr)  // 0\n\nok := into.CanInt(\"blah\") // false\nerr := into.Try(func() {\n    a = into.Int(\"blah\")\n}) // into.ErrInvalid{Value: \"blah\", Type: \"int\"}\nn, err := into.Maybe(into.Int, \"blah\") // 0, into.ErrInvalid{Value: \"blah\", Type: \"int\"}\n```\n\n## Performance\n\nThis library tries to avoid as much overhead as possible, and in many cases achieves zero allocation.\n\nBenchmarks on a M2 Mac Mini:\n\n```\nBenchmarkFloat-12                \t601534540\t        1.997 ns/op\t      0 B/op\t      0 allocs/op\nBenchmarkFloatWithOptions-12     \t444859920\t        2.692 ns/op\t      0 B/op\t      0 allocs/op\nBenchmarkFloatFallback-12        \t441497448\t        2.699 ns/op\t      0 B/op\t      0 allocs/op\nBenchmarkInt-12                  \t572993503\t        2.096 ns/op\t      0 B/op\t      0 allocs/op\nBenchmarkIntWithOptions-12       \t442683682\t        2.715 ns/op\t      0 B/op\t      0 allocs/op\nBenchmarkIntFallback-12          \t440095513\t        2.704 ns/op\t      0 B/op\t      0 allocs/op\nBenchmarkString-12               \t331075846\t        3.579 ns/op\t      0 B/op\t      0 allocs/op\nBenchmarkStringWithOptions-12    \t307433682\t        3.914 ns/op\t      0 B/op\t      0 allocs/op\nBenchmarkStringFallback-12       \t264048576\t        4.490 ns/op\t      0 B/op\t      0 allocs/op\nBenchmarkUint-12                 \t621541999\t        1.928 ns/op\t      0 B/op\t      0 allocs/op\nBenchmarkUintWithOptions-12      \t447733209\t        2.673 ns/op\t      0 B/op\t      0 allocs/op\nBenchmarkUintFallback-12         \t445057358\t        2.689 ns/op\t      0 B/op\t      0 allocs/op\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguregu%2Finto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguregu%2Finto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguregu%2Finto/lists"}