{"id":21658279,"url":"https://github.com/mmatczuk/go_generics","last_synced_at":"2025-04-16T02:13:48.192Z","repository":{"id":107078105,"uuid":"143997016","full_name":"mmatczuk/go_generics","owner":"mmatczuk","description":"Templates, generics engine for Go","archived":false,"fork":false,"pushed_at":"2018-12-12T14:37:52.000Z","size":37,"stargazers_count":136,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-16T02:13:32.420Z","etag":null,"topics":["generics","go"],"latest_commit_sha":null,"homepage":"","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/mmatczuk.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}},"created_at":"2018-08-08T10:17:39.000Z","updated_at":"2024-10-15T06:13:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"cedffae8-3594-4424-878d-492a209de1c3","html_url":"https://github.com/mmatczuk/go_generics","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmatczuk%2Fgo_generics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmatczuk%2Fgo_generics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmatczuk%2Fgo_generics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmatczuk%2Fgo_generics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mmatczuk","download_url":"https://codeload.github.com/mmatczuk/go_generics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249183111,"owners_count":21226143,"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":["generics","go"],"created_at":"2024-11-25T09:29:00.574Z","updated_at":"2025-04-16T02:13:48.175Z","avatar_url":"https://github.com/mmatczuk.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"## Generics [![Build Status](https://travis-ci.org/mmatczuk/go_generics.svg?branch=master)](https://travis-ci.org/mmatczuk/go_generics)\n\nThis project is bazel-free version of [Google go_generics tool](https://github.com/google/gvisor/blob/master/tools/go_generics) released with gVisor project. \n\nIt allows for generating code from template while still working with standard Go code. A great example of using it is [ScyllaDB go-set](https://github.com/scylladb/go-set) package.\n\n## Installation\n\n```bash\ngo get -u github.com/mmatczuk/go_generics/cmd/go_generics\ngo get -u github.com/mmatczuk/go_generics/cmd/go_merge\n```\n\n## go_generics\n\n`go_generics` reads a Go source file and writes a new version of that file with a few transformations applied to each. Namely:\n\n1. Global types can be explicitly renamed with the -t option. For example, if `-t=A=B` is passed in, all references to `A` will be replaced with references to `B`; a function declaration like:\n\n```go\nfunc f(arg *A)\n```\n\nwould be renamed to:\n\n```go\nfunc f(arg *B)\n```\n\n2. Global type definitions and their method sets will be removed when they're being renamed with `-t`. For example, if `-t=A=B` is passed in, the following definition and methods that existed in the input file wouldn't exist at all in the output file:\n\n```go\ntype A struct{}\n\nfunc (*A) f() {}\n```\n\n3. All global types, variables, constants and functions (not methods) are prefixed and suffixed based on the option `-prefix` and `-suffix` arguments. For example, if `-suffix=A` is passed in, the following globals:\n\n```go\nfunc f()\ntype t struct{}\n```\n\nwould be renamed to:\n\n```go\nfunc fA()\ntype tA struct{}\n```\n\nSome special tags are also modified. For example:\n\n```go\n\"state:.(t)\"\n```\n\nwould become:\n\n```go\n\"state:.(tA)\"\n```\n\n4. The package is renamed to the value via the `-p` argument. \n\n5. Value of constants can be modified with `-c` argument. Note that not just the top-level declarations are renamed, all references to them are also properly renamed as well, taking into account visibility rules and shadowing. For example, if `-suffix=A` is passed in, the following:\n\n```go\nvar b = 100\n\nfunc f() {\n\n    g(b)\n    b := 0\n    g(b)\n\n}\n```\n\nWould be replaced with:\n\n```go\nvar bA = 100\n\nfunc f() {\n\n    g(bA)\n    b := 0\n    g(b)\n\n}\n```\n\nNote that the second call to `g()` kept \"b\" as an argument because it refers to the local variable \"b\".\n\nUnfortunately, `go_generics` does not handle anonymous fields with renamed types.\n\n## go_merge\n\n`go_merge` merges multiple Go files into one, may be used in a pipeline before `go_generics`. \n\n## License\n\nThis project is distributed under the Apache 2.0 license. See the [LICENSE](https://github.com/scylladb/gocqlx/blob/master/LICENSE) file for details.\nIt contains software from:\n\n* [github.com/google/gvisor](https://github.com/google/gvisor), licensed under the Apache 2.0 license.\n\nGitHub star is always appreciated!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmatczuk%2Fgo_generics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmmatczuk%2Fgo_generics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmatczuk%2Fgo_generics/lists"}