{"id":44437142,"url":"https://github.com/levelfourab/conversions-go","last_synced_at":"2026-02-12T14:01:06.075Z","repository":{"id":171176198,"uuid":"628010783","full_name":"LevelFourAB/conversions-go","owner":"LevelFourAB","description":"Conversions for Go, with support for custom types, indirect conversions and error handling","archived":false,"fork":false,"pushed_at":"2026-02-11T00:53:45.000Z","size":45,"stargazers_count":0,"open_issues_count":7,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-11T04:08:00.921Z","etag":null,"topics":[],"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/LevelFourAB.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-04-14T17:42:57.000Z","updated_at":"2025-09-14T06:54:25.000Z","dependencies_parsed_at":"2025-12-04T22:09:23.649Z","dependency_job_id":null,"html_url":"https://github.com/LevelFourAB/conversions-go","commit_stats":null,"previous_names":["levelfourab/conversions-go"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/LevelFourAB/conversions-go","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LevelFourAB%2Fconversions-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LevelFourAB%2Fconversions-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LevelFourAB%2Fconversions-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LevelFourAB%2Fconversions-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LevelFourAB","download_url":"https://codeload.github.com/LevelFourAB/conversions-go/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LevelFourAB%2Fconversions-go/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29367813,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-12T08:51:36.827Z","status":"ssl_error","status_checked_at":"2026-02-12T08:51:26.849Z","response_time":55,"last_error":"SSL_read: 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":[],"created_at":"2026-02-12T14:00:53.096Z","updated_at":"2026-02-12T14:01:06.067Z","avatar_url":"https://github.com/LevelFourAB.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# conversions-go\n\nConversions is a module to convert between types in Go, with support for\n`reflect.Type` or a custom type indicator, custom conversion functions and\nindirect conversions.\n\n## Features\n\n- Uses generics in `Conversions` for type safety\n- Supports `reflect.Type` or a custom type indicator\n- Built-in conversions for `reflect.Type`\n- Error handling, conversions can safely error if values cannot be converted\n- Custom conversion functions can be registered\n- Indirect conversions, if a direct conversion is not found between two types\n  a chain of conversions will be searched for\n- Thread-safe\n  \n## Installation\n\n```bash\ngo get github.com/levelfourab/conversions-go\n```\n\n## Using\n\nIf you want to use conversions with your own types and information you need to\ncreate a `Conversions` using the `WithTypeExtractor` option. The type extractor\nis in charge of taking a value and returning the type indicator for that value.\n\nThis type is then used during conversion. If a direct conversion is not found\nbetween the two types, a chain of conversions will be searched for.\n\nExample:\n\n```go\ntype MediaType string\n\ntype StringWithMediaType struct {\n  MediaType MediaType\n  Value     string\n}\n\nconversions, err := conversions.New(\n  conversions.WithTypeExtractor(func(v StringWithMediaType) (MediaType, error) {\n    return v.MediaType, nil\n  }),\n)\n\nconversions.AddConversion(\"text/html\", \"text/plain\", func(v StringWithMediaType) (StringWithMediaType, error) {\n  // Using a hypothetical html2text package\n  return html2text.Convert(v.Value)\n})\n\n// Perform the conversion\nasPlainText, err := conversions.Convert(StringWithMediaType{\n  MediaType: \"text/html\",\n  Value:     \"\u003ch1\u003eHello World\u003c/h1\u003e\",\n}, \"text/plain\")\n```\n\n### With Go-types\n\nThe `types` sub-package is available for the most common use case, converting\nbetween Go types. Part of this includes default conversions for many built-in\ntypes such as `string`, `int` (and variants), `uint` (and variants), `float32`\nand `float64`.\n\nExample:\n\n```go\nconversions, err := types.New(\n  types.WithDefaultConversions(),\n)\n\n// Convert a string to an int, using types.TypeInt for convenience\nasInt, err := conversions.Convert(\"1\", types.TypeInt)\n\n// Or using reflect.Type directly\nasInt, err := conversions.Convert(\"1\", reflect.TypeOf(int(0)))\n```\n\nAliases are available to not have to carry generic types around:\n\n- `types.Conversions` is an alias for `conversions.Conversions[reflect.Type, any]`\n- `types.Converter` is an alias for `conversions.Converter[any]`\n- `types.Option` is an alias for `conversions.Option[reflect.Type, any]`\n\n## License\n\nconversions-go is licensed under the MIT License. See [LICENSE](LICENSE) for \nthe full license text.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flevelfourab%2Fconversions-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flevelfourab%2Fconversions-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flevelfourab%2Fconversions-go/lists"}