{"id":22387391,"url":"https://github.com/martinohmann/collections-gen","last_synced_at":"2025-03-26T21:13:40.518Z","repository":{"id":57609610,"uuid":"216389808","full_name":"martinohmann/collections-gen","owner":"martinohmann","description":"Code generator for golang collections","archived":false,"fork":false,"pushed_at":"2019-11-04T18:41:41.000Z","size":56,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-01T02:42:58.102Z","etag":null,"topics":["codegen","golang-collections","immutable-collections"],"latest_commit_sha":null,"homepage":null,"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/martinohmann.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-20T16:12:20.000Z","updated_at":"2022-10-29T13:08:07.000Z","dependencies_parsed_at":"2022-08-27T10:41:08.674Z","dependency_job_id":null,"html_url":"https://github.com/martinohmann/collections-gen","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/martinohmann%2Fcollections-gen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinohmann%2Fcollections-gen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinohmann%2Fcollections-gen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinohmann%2Fcollections-gen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/martinohmann","download_url":"https://codeload.github.com/martinohmann/collections-gen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245735882,"owners_count":20663807,"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":["codegen","golang-collections","immutable-collections"],"created_at":"2024-12-05T02:09:01.360Z","updated_at":"2025-03-26T21:13:40.495Z","avatar_url":"https://github.com/martinohmann.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"collections-gen\n===============\n\n[![Build Status](https://travis-ci.org/martinohmann/collections-gen.svg?branch=master)](https://travis-ci.org/martinohmann/collections-gen)\n[![Go Report Card](https://goreportcard.com/badge/github.com/martinohmann/collections-gen?style=flat)](https://goreportcard.com/report/github.com/martinohmann/collections-gen)\n[![GoDoc](https://godoc.org/github.com/martinohmann/collections-gen?status.svg)](https://godoc.org/github.com/martinohmann/collections-gen)\n\nCode generator for mutable and immutable golang collections. `collections-gen`\nis built on top of [gengo](https://github.com/kubernetes/gengo) and can\ngenerate collections code based on tags in the doc blocks preceeding a type. It\nidentifies the types needing code generation by the comment tag\n`+collections-gen`.\n\nIf you are looking for ready-to-use collections for builtin types and generic\nslices, check out the\n[collections-go](https://github.com/martinohmann/collections-go) package.\n\nSimple example\n--------------\n\nGiven you have a type `Foo`, add the `+collections-gen=true` tag to the 1st or\n2nd doc block preceeding the type definition:\n\n```go\n// +collections-gen=true\n//\n// Foo is a custom type.\ntype Foo struct {\n    ...\n}\n```\n\nTo generate a collection for the `Foo` type, run `collections-gen` with the input and output packages as arguments:\n\n```sh\ncollections-gen -i pkg/path/to/foo -o pkg/path/to/generated/collection\n```\n\nFor example:\n\n```sh\ncollections-gen -i github.com/martinohmann/mylib/foo -o github.com/martinohmann/mylib/foo/collections\n```\n\nThe code generator will generate the file `foo_collection.go` containing the\n`FooCollection` type in `github.com/martinohmann/mylib/foo/collections`.\n\nCheck out [examples/simple](examples/simple/) for the example code.\n\n**Hint:** You can also make use of `go generate` by adding a machine readable comment to your source files:\n\n```go\n//go:generate collections-gen -i pkg/path/to/foo -o pkg/path/to/generated/collection\n```\n\nAfterwards you can generate your custom collections by running:\n\n```sh\ngo generate ./...\n```\n\nNaming\n------\n\nBy default the generated collections are named `ElementTypeCollection` and\n`ImmutableElementTypeCollection` for immutable collections, where `ElementType`\nis the element type of the collection. The default output files follow the same\nconvention just in snake case: `element_type_collection.go` and\n`immutable_element_type_collection.go`. For overriding the naming behaviour\nhave a look at the `name` and `out-name` options in the [customizing generated\ncollections](#customizing-generated-collections) section.\n\nCustomizing generated collections\n---------------------------------\n\nTo customize the generator behaviour for a given type, the comment tag\n`+collections-gen:options` can be added. Adding it multiple times causes the\ngeneration of multiple collection types. The `+collections-gen:options` tag\naccepts configuration flags of the following form:\n\n```go\n// +collections-gen:options=flag1=value1,boolflag1,flag2=value2,boolflag2\n```\n\n### Supported flags\n\n| Flag            | Type     | Description                                                                                                                                                                     |\n| ----            | ----     | -----------                                                                                                                                                                     |\n| `mutable`       | `bool`   | If set, the generated collection will be mutable (default).                                                                                                                     |\n| `immutable`     | `bool`   | If set, the generated collection will be immutable.                                                                                                                             |\n| `pointer`       | `bool`   | If set, the collection elements are pointers.                                                                                                                                   |\n| `underlying`    | `bool`   | If the type is an alias, use the underlying type for the collection elements.                                                                                                   |\n| `equality-func` | `string` | Specify a custom func for equality checks. If left out, `reflect.DeepEqual` will be used for slice, map and func types. For everything else plain `==` comparison will be used. |\n| `name`          | `string` | Specify a custom name for the generated collection type.                                                                                                                        |\n| `out-name`      | `string` | Specify a custom name for the generated go file (without the `.go` extension).                                                                                                  |\n| `prefix`        | `string` | The name prefix for the generated collection. Defaults to `immutable` if the collection is immutable. Will be ignored if `name` is set.                                         |\n| `suffix`        | `string` | The name suffix for the generated collection. Defaults to `collection`. Will be ignored if `name` is set.                                                                       |\n| `noprefix`      | `bool`   | Disables adding the collection name prefix.                                                                                                                                     |\n| `nosuffix`      | `bool`   | Disables adding the collection name suffix.                                                                                                                                     |\n\n### Custom options example\n\n```go\n// +collections-gen=true\n//\n// Generate FooCollection with *Foo element type.\n//\n// +collections-gen:options=pointer\n//\n// Generate an immutable collection with Foo element type and name\n// BarCollection and write it into collection.go in the output package.\n//\n// +collections-gen:options=immutable,name=BarCollection,out-name=collection\n//\n// Foo is a custom type.\ntype Foo struct {\n\tBar string\n}\n```\n\nCheck out the examples in the [examples](examples/) directory to see all\noptions in action.\n\nLicense\n-------\n\nThe source code of collections-gen is released under the MIT License. See the\nbundled LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinohmann%2Fcollections-gen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmartinohmann%2Fcollections-gen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinohmann%2Fcollections-gen/lists"}