{"id":42122710,"url":"https://github.com/kpeu3i/fielder","last_synced_at":"2026-01-26T14:35:07.262Z","repository":{"id":50666860,"uuid":"519775154","full_name":"kpeu3i/fielder","owner":"kpeu3i","description":"A Go tool to auto generate ENUM for struct fields","archived":false,"fork":false,"pushed_at":"2025-04-25T16:15:16.000Z","size":39,"stargazers_count":8,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-25T17:34:32.093Z","etag":null,"topics":["code-generation","enum","golang","orm-library"],"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/kpeu3i.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-31T12:50:46.000Z","updated_at":"2025-04-25T16:23:24.000Z","dependencies_parsed_at":"2022-08-12T22:00:55.414Z","dependency_job_id":null,"html_url":"https://github.com/kpeu3i/fielder","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/kpeu3i/fielder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kpeu3i%2Ffielder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kpeu3i%2Ffielder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kpeu3i%2Ffielder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kpeu3i%2Ffielder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kpeu3i","download_url":"https://codeload.github.com/kpeu3i/fielder/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kpeu3i%2Ffielder/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28780350,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T13:55:28.044Z","status":"ssl_error","status_checked_at":"2026-01-26T13:55:26.068Z","response_time":59,"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":["code-generation","enum","golang","orm-library"],"created_at":"2026-01-26T14:35:06.592Z","updated_at":"2026-01-26T14:35:07.257Z","avatar_url":"https://github.com/kpeu3i.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fielder\n\n*Fielder* is a tool that generates Go code. It extracts fields from a struct and transforms them into ENUM.\nAlso, it adds useful types, methods and functions. \n\n## Motivation\n\nWhen using ORM-s like `gorm`, `go-pg`, `bun` you have to pass column names as arguments to different methods.\nIt is a pain to use raw strings for that, and it also might be a security risk.\nIt is better to rely on ENUM which represents columns for a specific table.  \nAlso, the generated field names can be used in combination with Golang reflection (`FieldByName`) for different purposes.\n\n## Features\n\nThe library provides the following features:\n\n  * Struct fields represented in an ENUM.\n  * Different functions and methods to work with the ENUM (validation, listing, conversion to string, etc).\n  * Tag-based field names extraction (regex can be used to extract a value from a tag).\n  * Embedded fields extraction.\n  * Field exclusion.\n  * Different formatting (camel, pascal, snake).\n  * Template overriding.\n\n## Installation\n\n    go install github.com/kpeu3i/fielder@v1.6.0\n\n## Usage\n\nPut the `go:generate` directive in the same package as the struct you want to generate.\nFor example:\n\n```go\n//go:generate fielder -type=UserAccount\n\npackage models\n \ntype UserAccount struct {\n    FirstName string\n    LastName  string\n    Email     string\n    Password  string\n}\n```\n\nThen, run command bellow to generate the code:\n\n    $ go generate ./...\n\nThe following formatting strategies can be applied to the extracted field names (see `format` and `tag_format` flag):\n * `snake_case` (e.g `first_name`)\n * `camel_case` (e.g `firstName`)\n * `pascal_case` (e.g `FirstName`)\n\nFor more details, check the [examples](examples) folder in the project root. \n\nThe following CLI flags are allowed:\n\n```\nUsage of fielder:\n  -embedded\n    \tExtract embedded fields (default false)\n  -excluded string\n    \tComma separated list of excluded fields (default \"\")\n  -format string\n    \tFormat of the generated type values extracted from the struct field (default \"as_is\")\n  -output string\n    \tSet output filename (default \"\u003csrc_dir\u003e/\u003ctype\u003e_fielder.go\")\n  -pkg string\n    \tPackage name to extract type from (default \".\")\n  -suffix string\n    \tSuffix for the generated struct (default \"Field\")\n  -tag string\n    \tTag to extract field values from (default \"\")\n  -tag_format string\n    \tFormat of the generated type values extracted from the tag (default \"as_is\")\n  -tag_regexp string\n    \tRegular expression to parse field value from a tag (default \"\")\n  -tag_strict\n    \tStrict mode for tag parsing (returns error if tag is not found)\n  -tpl string\n    \tSet template filename (default \"\")\n  -type string\n    \tType to extract fields from\n```\n\n## Generated types, functions and methods\n\nWhen *Fielder* is applied to a type, it will generate public functions/methods and types:\n\n* Type `\u003cType\u003e\u003cSuffix\u003e` represents fields ENUM:\n    * Method `\u003cType\u003e\u003cSuffix\u003e::IsValid` returns true if the value is a valid ENUM.\n    * Method `\u003cType\u003e\u003cSuffix\u003e::String` returns the string representation of the value.\n* Type `\u003cType\u003e\u003cSuffix\u003eList` represents collection of ENUM fields:\n    * Method `\u003cType\u003e\u003cSuffix\u003eList::Len` returns the number of values in the collection.\n    * Method `\u003cType\u003e\u003cSuffix\u003eList::IsEmpty` returns true if the collection is empty.\n    * Method `\u003cType\u003e\u003cSuffix\u003eList::Contains` returns true if the collection contains the value.\n    * Method `\u003cType\u003e\u003cSuffix\u003eList::Equals` returns true if the two collections are equal.\n    * Method `\u003cType\u003e\u003cSuffix\u003eList::Similar` returns true if the two collections contain the same values.\n    * Method `\u003cType\u003e\u003cSuffix\u003eList::Add` adds the values to the collection.\n    * Method `\u003cType\u003e\u003cSuffix\u003eList::AddIfNotContains` adds the values to the collection if they are not already present.\n    * Method `\u003cType\u003e\u003cSuffix\u003eList::Remove` removes the values from the collection.\n    * Method `\u003cType\u003e\u003cSuffix\u003eList::Clear` clears the collection.\n    * Method `\u003cType\u003e\u003cSuffix\u003eList::Clone` returns a pointer to a copy of the collection.\n    * Method `\u003cType\u003e\u003cSuffix\u003eList::Strings` returns a slice with all the strings of the collection items.\n* Functions:\n    * `\u003cType\u003e\u003cSuffix\u003eValues` returns a slice with all the values of the ENUM.\n    * `\u003cType\u003e\u003cSuffix\u003eStrings` returns a slice with all the strings of the ENUM.\n    * `New\u003cType\u003e\u003cSuffix\u003e` returns a new collection with all the values of the ENUM.\n    * `New\u003cType\u003e\u003cSuffix\u003eWith` returns a new collection with the given values of the ENUM.\n\n## Inspiring projects\n  * [enumer](https://github.com/dmarkham/enumer)\n  * [stringer](https://pkg.go.dev/golang.org/x/tools/cmd/stringer)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkpeu3i%2Ffielder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkpeu3i%2Ffielder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkpeu3i%2Ffielder/lists"}