{"id":37162822,"url":"https://github.com/phelmkamp/metatag","last_synced_at":"2026-01-14T19:22:28.792Z","repository":{"id":36481808,"uuid":"226545922","full_name":"phelmkamp/metatag","owner":"phelmkamp","description":"Go metaprogramming using struct tags + generate","archived":false,"fork":false,"pushed_at":"2022-03-25T18:12:06.000Z","size":104,"stargazers_count":7,"open_issues_count":3,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-14T20:52:49.751Z","etag":null,"topics":["boilerplate","codegenerator","filter","getter","golang","mapper","metaprogramming","setter"],"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/phelmkamp.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-12-07T16:50:00.000Z","updated_at":"2023-09-05T08:30:35.000Z","dependencies_parsed_at":"2022-08-08T15:01:46.232Z","dependency_job_id":null,"html_url":"https://github.com/phelmkamp/metatag","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/phelmkamp/metatag","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phelmkamp%2Fmetatag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phelmkamp%2Fmetatag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phelmkamp%2Fmetatag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phelmkamp%2Fmetatag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phelmkamp","download_url":"https://codeload.github.com/phelmkamp/metatag/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phelmkamp%2Fmetatag/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28432586,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T18:57:19.464Z","status":"ssl_error","status_checked_at":"2026-01-14T18:52:48.501Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["boilerplate","codegenerator","filter","getter","golang","mapper","metaprogramming","setter"],"created_at":"2026-01-14T19:22:28.029Z","updated_at":"2026-01-14T19:22:28.782Z","avatar_url":"https://github.com/phelmkamp.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# metatag\nGo metaprogramming using struct tags + generate\n\n# Installation\n\n`go get github.com/phelmkamp/metatag`\n\n# Usage\n\n1. Define struct tags\n\n\tFormat is `meta:\"directive[,option][;directive2]\"`. For example:\n\t```go\n\ttype Foo struct {\n\t\tname, Desc string   `meta:\"getter\"`\n\t\tsize       int      `meta:\"ptr;getter;setter\"`\n\t\tlabels     []string `meta:\"setter;getter;mapper,int\"`\n\t}\n\t```\n\n2. Run command\n\n\t```bash\n\tmetatag --path=$SRCDIR\n\t```\n\n\tBetter yet, add the following comment to a file at the root of your source tree (e.g. main.go)\n\tand run `go generate` as part of your build process.\n\n\t```go\n\t//go:generate metatag\n\t```\n\n3. Enjoy!\n\n\tA *_meta.go file is generated for each *.go file that has meta tags.\n\tYou can review/modify the generated code, write corresponding tests, etc!\n\tJust be aware that any changes will be overwritten the next time the tool runs.\n\n# Directives\n\n`getter`\n\nGenerates a getter. Method name is the name of the field.\n`Get` is prepended to the name if and only if the field is already exported.\nUses value receiver by default.\n\n`setter`\n\nGenerates a setter. Method name is the name of the field prepended with `Set`.\nAlways uses pointer receiver.\n\n`filter` (slice only)\n\nGenerates a method that returns a copy of the slice, omitting elements that are rejected by the given function.\nMethod name is `Filter` followed by the name of the field. Includes a `Filter*N` method to support limit/contains/findFirst functionality.\nUses value receiver by default.\n\nOptions\n* `omitfield`: exclude field name from method (i.e. just `Filter`) \n* `chain`: store result in-place and return the receiver (facilitates method chaining)\n\n`mapper,$type` (slice only)\n\nGenerates a method that returns the result of mapping all elements to the specified type using the given function.\nMethod name is of the form `MapFieldTo$Type`, or just `MapTo$Type` if `omitfield` is specified.\nUses value receiver by default.\n\n`sort` (slice only)\n\nGenerates `Len` and `Swap` methods to implement [sort.Interface](https://golang.org/pkg/sort/#Interface), along with a `Sort` convenience method.\nA `Less` method can be implemented separately or generated using one of the options.\nUses value receivers by default.\n\nOptions\n* `stringer`: generate a `Less` method that compares elements by their string representations \n* `func`: generate a `Less` method that accepts a less function\n\n`wrapper` (slice only)\n\nIndicates that the struct is a \"wrapper\" for the given slice. Enables `omitfield` and `chain` options for all subsequent directives.\n\nSee [person.Persons](internal/testdata/person/person.go) for an example.\n\n`stringer`\n\nIncludes the field in the result of the generated `String` method. Uses value receiver by default.\n\n`new`\n\nIncludes the field as an argument to the generated `New$Type` method.\n\n`equal`\n\nIncludes the field in the generated `Equal` method.\nSpecify the `reflect` option to compare the field using `reflect.DeepEqual`.\nUses value receiver by default.\n\n`ptr`\n\nSpecifies that a pointer receiver be used for all subsequent directives.\n\n# FAQ\n\n1. Why generate getters and setters?\n\n\tGetters/setters are sometimes necessary to adhere to a \"data contract\" since [Go interfaces only match methods, not fields](https://github.com/golang/go/issues/23796).\n\tGetters/setters are great candidates for code generation because they are true boilerplate where names and types directly correspond to a particular field.\n\n2. Why code generation instead of reflection?\n\n\tCode generation provides compile-time type safety which is a critical feature of Go and languages like it.\n\tPlus, generation produces easy-to-understand code that you can review and modify as you see fit!\n\n3. Why struct tags?\n\n\tStruct tags are well suited for this task because they are designed to provide auxilliary information to tools/packages in a concise and unobtrusive way.\n\tAlso, generating methods for a struct gives us a nice \"namespace\" with a low probability of collisions (as opposed to package-level functions).\n\t\n4. What is a slice wrapper?\n\n\tA slice wrapper is a struct that contains a slice, allowing you to define methods that operate on the slice. This is similar to the [slice types](https://golang.org/pkg/sort/#StringSlice) in the sort package, but by using a struct we can define meta tags for the desired functionality. The methods can also return the wrapper type to support chaining.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphelmkamp%2Fmetatag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphelmkamp%2Fmetatag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphelmkamp%2Fmetatag/lists"}