{"id":19288518,"url":"https://github.com/samber/go-type-to-string","last_synced_at":"2025-04-22T04:33:36.060Z","repository":{"id":196368217,"uuid":"695979184","full_name":"samber/go-type-to-string","owner":"samber","description":"🕵️‍♂️ Extract a string representation of Go type","archived":false,"fork":false,"pushed_at":"2024-11-09T18:03:36.000Z","size":44,"stargazers_count":14,"open_issues_count":7,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-11-09T19:17:48.158Z","etag":null,"topics":["go","reflect","reflection","string","type"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/samber/go-type-to-string","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/samber.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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":["samber"]}},"created_at":"2023-09-24T19:30:18.000Z","updated_at":"2024-11-09T18:02:23.000Z","dependencies_parsed_at":"2023-09-24T21:04:17.761Z","dependency_job_id":"474400ea-b4b6-45e6-b9e9-168053a5875a","html_url":"https://github.com/samber/go-type-to-string","commit_stats":null,"previous_names":["samber/go-type-to-string"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samber%2Fgo-type-to-string","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samber%2Fgo-type-to-string/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samber%2Fgo-type-to-string/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samber%2Fgo-type-to-string/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samber","download_url":"https://codeload.github.com/samber/go-type-to-string/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223888365,"owners_count":17220083,"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":["go","reflect","reflection","string","type"],"created_at":"2024-11-09T22:09:15.372Z","updated_at":"2024-11-09T22:09:15.959Z","avatar_url":"https://github.com/samber.png","language":"Go","readme":"\n# Extract a string representation of Go type\n\n[![tag](https://img.shields.io/github/tag/samber/go-type-to-string.svg)](https://github.com/samber/go-type-to-string/releases)\n![Go Version](https://img.shields.io/badge/Go-%3E%3D%201.18.0-%23007d9c)\n[![GoDoc](https://godoc.org/github.com/samber/go-type-to-string?status.svg)](https://pkg.go.dev/github.com/samber/go-type-to-string)\n![Build Status](https://github.com/samber/go-type-to-string/actions/workflows/test.yml/badge.svg)\n[![Go report](https://goreportcard.com/badge/github.com/samber/go-type-to-string)](https://goreportcard.com/report/github.com/samber/go-type-to-string)\n[![Coverage](https://img.shields.io/codecov/c/github/samber/go-type-to-string)](https://codecov.io/gh/samber/go-type-to-string)\n[![Contributors](https://img.shields.io/github/contributors/samber/go-type-to-string)](https://github.com/samber/go-type-to-string/graphs/contributors)\n[![License](https://img.shields.io/github/license/samber/go-type-to-string)](./LICENSE)\n\n## Motivations\n\nFor the [samber/do](https://github.com/samber/do) project, I needed to convert a Go type into a string. I used to convert it with `fmt.Sprintf(\"%T\", t)` -\u003e `mypkg.MyStruct`, but it does not insert package path into type representation, leading to collision when types from different pacakges match.\n\nThis package export type using the following representation:\n\n```go\n  *[]**\u003c-chan   github.com/samber/example    .Example\n  |             |                            ^\n  |             |                            Type name\n  |             ^\n  |             The package path (including package name)\n  ^\n  Type indicators (map, slice, pointer, channel...)\n```\n\nThis library supports:\n- primitive types\n- pointers\n- structs\n- functions with input and output\n- vaargs\n- interfaces\n- maps\n- arrays\n- slices\n- channels\n- generics\n- anonymous types\n- named types\n\nKnown limitations:\n- structs in anonymous types\n- structs in generic type\n- `any(\"foobar\")` is currently reported as `any` instead of `string` (see [#2](https://github.com/samber/go-type-to-string/issues/2))\n\n## Examples\n\nUsing the following types:\n\n```go\npackage example\n\ntype testStruct struct{}\ntype testGeneric[T any] struct{ t T }\ntype testNamedType testStruct\n```\n\n| Type                                         | Exported                                                                                         |\n| -------------------------------------------- | ------------------------------------------------------------------------------------------------ |\n| `int`                                        | `int`                                                                                            |\n| `*int`                                       | `*int`                                                                                           |\n| `**[]*int`                                   | `**[]*int`                                                                                       |\n| `**[]*map[int]bool`                          | `**[]*map[int]bool`                                                                              |\n| `func (a string, b bool) int`                | `func (string, bool) int`                                                                        |\n| `func(int, ...string) (bool, error)`         | `func(int, ...string) (bool, error)`                                                             |\n| `testStruct`                                 | `github.com/samber/example.testStruct`                                                           |\n| `*testStruct`                                | `*github.com/samber/example.testStruct`                                                          |\n| `***testStruct`                              | `***github.com/samber/example.testStruct`                                                        |\n| `***testNamedType`                           | `***github.com/samber/example.testNamedType`                                                     |\n| `[][3]***testStruct`                         | `[][3]***github.com/samber/example.testStruct`                                                   |\n| `testGeneric[string]`                        | `github.com/samber/example.testGeneric[string]`                                                  |\n| `*map[testStruct]chan\u003c- testGeneric[string]` | `*map[github.com/samber/example.testStruct]chan\u003c- github.com/samber/example.testGeneric[string]` |\n\nSee more examples [here](https://github.com/samber/go-type-to-string/blob/main/converter_test#L13)\n\n## 🚀 Install\n\n```sh\ngo get github.com/samber/go-type-to-string\n```\n\nThis library is v1 and follows SemVer strictly. No breaking changes will be made to exported APIs before v2.0.0.\n\n## 💡 How to\n\nGoDoc: [https://pkg.go.dev/github.com/samber/go-type-to-string](https://pkg.go.dev/github.com/samber/go-type-to-string)\n\n```go\npackage example\n\nimport converter \"github.com/samber/go-type-to-string\"\n\ntype Example struct{\n    foo string\n    bar int\n}\n\nfunc main() {\n    name1 := converter.GetType[*Example]()\n    // \"*github.com/samber/example.Example\"\n\n    name2 := converter.GetValueType(Example{})\n    // \"github.com/samber/example.Example\"\n}\n```\n\n## 🤝 Contributing\n\n- Ping me on Twitter [@samuelberthe](https://twitter.com/samuelberthe) (DMs, mentions, whatever :))\n- Fork the [project](https://github.com/samber/go-type-to-string)\n- Fix [open issues](https://github.com/samber/go-type-to-string/issues) or request new features\n\nDon't hesitate ;)\n\n```bash\n# Install some dev dependencies\nmake tools\n\n# Run tests\nmake test\n# or\nmake watch-test\n```\n\n## 👤 Contributors\n\n![Contributors](https://contrib.rocks/image?repo=samber/go-type-to-string)\n\n## 💫 Show your support\n\nGive a ⭐️ if this project helped you!\n\n[![GitHub Sponsors](https://img.shields.io/github/sponsors/samber?style=for-the-badge)](https://github.com/sponsors/samber)\n\n## 📝 License\n\nCopyright © 2023 [Samuel Berthe](https://github.com/samber).\n\nThis project is [MIT](./LICENSE) licensed.\n","funding_links":["https://github.com/sponsors/samber"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamber%2Fgo-type-to-string","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamber%2Fgo-type-to-string","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamber%2Fgo-type-to-string/lists"}