{"id":13412961,"url":"https://github.com/abice/go-enum","last_synced_at":"2026-01-16T16:24:00.264Z","repository":{"id":37842598,"uuid":"99968554","full_name":"abice/go-enum","owner":"abice","description":"An enum generator for go","archived":false,"fork":false,"pushed_at":"2025-10-17T20:10:36.000Z","size":7870,"stargazers_count":879,"open_issues_count":13,"forks_count":62,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-10-18T22:01:22.461Z","etag":null,"topics":["enum","generated","go","golang"],"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/abice.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":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2017-08-10T22:07:31.000Z","updated_at":"2025-10-17T20:09:57.000Z","dependencies_parsed_at":"2024-01-08T15:03:00.277Z","dependency_job_id":"70357743-19e4-4b8b-93d6-4f95b0c0f800","html_url":"https://github.com/abice/go-enum","commit_stats":null,"previous_names":[],"tags_count":49,"template":false,"template_full_name":null,"purl":"pkg:github/abice/go-enum","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abice%2Fgo-enum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abice%2Fgo-enum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abice%2Fgo-enum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abice%2Fgo-enum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abice","download_url":"https://codeload.github.com/abice/go-enum/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abice%2Fgo-enum/sbom","scorecard":{"id":161039,"data":{"date":"2025-08-11","repo":{"name":"github.com/abice/go-enum","commit":"8ecdc97214ef9cddc75f0e09d01dd973caaa59ce"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":5.1,"checks":[{"name":"Code-Review","score":2,"reason":"Found 4/16 approved changesets -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":10,"reason":"12 commit(s) and 13 issue activity found in the last 90 days -- score normalized to 10","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/build_and_test.yml:1","Warn: no topLevel permission defined: .github/workflows/release.yml:1","Warn: no topLevel permission defined: .github/workflows/release_check.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build_and_test.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/abice/go-enum/build_and_test.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build_and_test.yml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/abice/go-enum/build_and_test.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/build_and_test.yml:38: update your workflow using https://app.stepsecurity.io/secureworkflow/abice/go-enum/build_and_test.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build_and_test.yml:45: update your workflow using https://app.stepsecurity.io/secureworkflow/abice/go-enum/build_and_test.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/build_and_test.yml:58: update your workflow using https://app.stepsecurity.io/secureworkflow/abice/go-enum/build_and_test.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/abice/go-enum/release.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/abice/go-enum/release.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/abice/go-enum/release.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/abice/go-enum/release.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:38: update your workflow using https://app.stepsecurity.io/secureworkflow/abice/go-enum/release.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release_check.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/abice/go-enum/release_check.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release_check.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/abice/go-enum/release_check.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/release_check.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/abice/go-enum/release_check.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/release_check.yml:30: update your workflow using https://app.stepsecurity.io/secureworkflow/abice/go-enum/release_check.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/release_check.yml:38: update your workflow using https://app.stepsecurity.io/secureworkflow/abice/go-enum/release_check.yml/master?enable=pin","Info:   0 out of   7 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   8 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Packaging","score":10,"reason":"packaging workflow detected","details":["Info: Project packages its releases by way of GitHub Actions.: .github/workflows/release.yml:9"],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Branch-Protection","score":8,"reason":"branch protection is not maximal on development and all release branches","details":["Info: 'allow deletion' disabled on branch 'master'","Info: 'force pushes' disabled on branch 'master'","Warn: 'branch protection settings apply to administrators' is disabled on branch 'master'","Info: 'stale review dismissal' is required to merge on branch 'master'","Warn: required approving review count is 1 on branch 'master'","Info: codeowner review is required on branch 'master'","Info: 'last push approval' is required to merge on branch 'master'","Info: 'up-to-date branches' is required to merge on branch 'master'","Info: status check found to merge onto on branch 'master'","Info: PRs are required in order to make changes on branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Signed-Releases","score":0,"reason":"Project has not signed or included provenance with any releases.","details":["Warn: release artifact v0.9.1 not signed: https://api.github.com/repos/abice/go-enum/releases/237074743","Warn: release artifact v0.9.0 not signed: https://api.github.com/repos/abice/go-enum/releases/234102840","Warn: release artifact v0.8.0 not signed: https://api.github.com/repos/abice/go-enum/releases/234094364","Warn: release artifact v0.7.0 not signed: https://api.github.com/repos/abice/go-enum/releases/225904640","Warn: release artifact v0.6.1 not signed: https://api.github.com/repos/abice/go-enum/releases/206708403","Warn: release artifact v0.9.1 does not have provenance: https://api.github.com/repos/abice/go-enum/releases/237074743","Warn: release artifact v0.9.0 does not have provenance: https://api.github.com/repos/abice/go-enum/releases/234102840","Warn: release artifact v0.8.0 does not have provenance: https://api.github.com/repos/abice/go-enum/releases/234094364","Warn: release artifact v0.7.0 does not have provenance: https://api.github.com/repos/abice/go-enum/releases/225904640","Warn: release artifact v0.6.1 does not have provenance: https://api.github.com/repos/abice/go-enum/releases/206708403"],"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 28 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-16T13:26:07.487Z","repository_id":37842598,"created_at":"2025-08-16T13:26:07.487Z","updated_at":"2025-08-16T13:26:07.487Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28479760,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"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":["enum","generated","go","golang"],"created_at":"2024-07-30T20:01:31.639Z","updated_at":"2026-01-16T16:24:00.256Z","avatar_url":"https://github.com/abice.png","language":"Go","readme":"# go-enum\n\n[![Actions Status](https://github.com/abice/go-enum/actions/workflows/build_and_test.yml/badge.svg)](https://github.com/abice/go-enum/actions/workflows/build_and_test.yml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/abice/go-enum)](https://goreportcard.com/report/github.com/abice/go-enum)\n[![Coverage Status](https://coveralls.io/repos/github/abice/go-enum/badge.svg)](https://coveralls.io/github/abice/go-enum)\n[![GoDoc](https://godoc.org/github.com/abice/go-enum?status.svg)](https://godoc.org/github.com/abice/go-enum)\n[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)\n\nAn enum generator for Go that creates type-safe enumerations with useful methods from simple type declarations.\n\n## Key Features\n\n- 🎯 **Type-safe enums** - Generate const declarations with proper typing\n- 🔄 **String conversion** - Automatic `String()` and `Parse()` methods\n- 📦 **JSON marshaling** - Built-in JSON marshal/unmarshal support\n- 🗄️ **SQL integration** - Database scan and value functions\n- 🧪 **Custom templates** - Extend with your own code generation\n- ✅ **Multiple types** - Support for `int`, `string`, and other base types\n- 🏷️ **Flexible syntax** - Simple comment-based enum declarations\n\n## Table of Contents\n\n- [Key Features](#key-features)\n- [Requirements](#requirements)\n- [Quick Start](#quick-start)\n- [How it works](#how-it-works)\n- [String typed enums](#now-with-string-typed-enums)\n- [Recent Features](#recent-features)\n- [Goal](#goal)\n- [Docker image](#docker-image)\n- [Installation](#installation)\n- [Adding it to your project](#adding-it-to-your-project)\n- [Command options](#command-options)\n- [Syntax](#syntax)\n- [Examples](#example)\n\n## Requirements\n\n- Go 1.24.0 or later (recommended for new tool installation method)\n- Go 1.23.0 or later (minimum for legacy installation)\n\n## Quick Start\n\n1. Install go-enum as a project tool (Go 1.24+):\n\n   ```shell\n   go get -tool github.com/abice/go-enum@latest\n   ```\n\n   Or for older Go versions:\n\n   ```shell\n   go install github.com/abice/go-enum@latest\n   ```\n\n2. Create a Go file with an enum declaration:\n\n   ```go\n   package main\n   \n   // ENUM(red, green, blue)\n   type Color int\n   ```\n\n3. Generate the enum:\n\n   ```shell\n   # Go 1.24+ (recommended)\n   go tool go-enum -f your_file.go\n   \n   # Or for older Go versions\n   go-enum -f your_file.go\n   ```\n\n4. Use your generated enum:\n\n   ```go\n   color := ColorRed\n   fmt.Println(color.String()) // prints \"red\"\n   \n   parsed, err := ParseColor(\"green\")\n   if err == nil {\n       fmt.Println(parsed) // prints \"green\"\n   }\n   ```\n\n## How it works\n\ngo-enum will take a commented type declaration like this:\n\n```go\n// ENUM(jpeg, jpg, png, tiff, gif)\ntype ImageType int\n```\n\nand generate a file with the iota definition along various optional niceties that you may need:\n\n```go\nconst (\n // ImageTypeJpeg is a ImageType of type Jpeg.\n ImageTypeJpeg ImageType = iota\n // ImageTypeJpg is a ImageType of type Jpg.\n ImageTypeJpg\n // ImageTypePng is a ImageType of type Png.\n ImageTypePng\n // ImageTypeTiff is a ImageType of type Tiff.\n ImageTypeTiff\n // ImageTypeGif is a ImageType of type Gif.\n ImageTypeGif\n)\n\n// String implements the Stringer interface.\nfunc (x ImageType) String() string\n\n// ParseImageType attempts to convert a string to a ImageType.\nfunc ParseImageType(name string) (ImageType, error)\n\n// MarshalText implements the text marshaller method.\nfunc (x ImageType) MarshalText() ([]byte, error)\n\n// UnmarshalText implements the text unmarshaller method.\nfunc (x *ImageType) UnmarshalText(text []byte) error\n```\n\n**Fear not the fact that the `MarshalText` and `UnmarshalText` are generated rather than JSON methods... they will still be utilized by the default JSON encoding methods.**\n\nIf you find that the options given are not adequate for your use case, there is an option to add a custom template (`-t` flag) to the processing engine so that your custom code can be created!\n\n## Now with string typed enums\n\n```go\n// ENUM(pending, running, completed, failed)\ntype StrState string\n```\n\n```go\nconst (\n // StrStatePending is a StrState of type pending.\n StrStatePending StrState = \"pending\"\n // StrStateRunning is a StrState of type running.\n StrStateRunning StrState = \"running\"\n // StrStateCompleted is a StrState of type completed.\n StrStateCompleted StrState = \"completed\"\n // StrStateFailed is a StrState of type failed.\n StrStateFailed StrState = \"failed\"\n)\n```\n\nIf you would like to get integer values in sql, but strings elsewhere, you can assign an int value in the declaration\nlike always, and specify the `--sqlint` flag.  Those values will be then used to convey the int value to sql, while allowing you to use only strings elsewhere.\nThis might be helpful for things like swagger docs where you want the same type being used on the api layer, as you do in the\nsql layer, and not have swagger assume that your enumerations are integers, but are in fact strings!\n\n```go\n// swagger:enum StrState\n// ENUM(pending, running, completed, failed)\ntype StrState string\n```\n\n## Recent Features\n\n### Custom JSON Package Support (v0.7.0+)\n\nYou can now specify a custom JSON package for imports instead of the standard `encoding/json`:\n\n```shell\ngo-enum --marshal --jsonpkg=\"github.com/goccy/go-json\" -f your_file.go\n```\n\n### Disable iota (v0.9.0+)\n\nFor cases where you don't want to use `iota` in your generated enums:\n\n```shell\ngo-enum --no-iota -f your_file.go\n```\n\n### Custom Output Suffix\n\nChange the default `_enum.go` suffix to something else:\n\n```shell\ngo-enum --output-suffix=\"_generated\" -f your_file.go  # Creates your_file_generated.go\n```\n\n## Goal\n\nThe goal of go-enum is to create an easy to use enum generator that will take a decorated type declaration like `type EnumName int` and create the associated constant values and funcs that will make life a little easier for adding new values.\nIt's not perfect, but I think it's useful.\n\nI took the output of the [Stringer](https://godoc.org/golang.org/x/tools/cmd/stringer) command as the `String()` method, and added a way to parse a string value.\n\n## Docker image\n\nYou can use the Docker image directly for running the command if you do not wish to install anything locally:\n\n```shell\ndocker run -w /app -v $(pwd):/app abice/go-enum:latest\n```\n\n## Installation\n\n### Using go get -tool (Go 1.24+, recommended)\n\nInstall go-enum as a project tool with dependency tracking in `go.mod`:\n\n```shell\ngo get -tool github.com/abice/go-enum@latest\n```\n\nThis will add a tool dependency to your `go.mod` file:\n\n```mod\ntool github.com/abice/go-enum\n```\n\nYou can then run the tool using:\n\n```shell\ngo tool go-enum [options]\n```\n\n### Using go install (older Go versions)\n\nInstall the latest version directly from source:\n\n```shell\ngo install github.com/abice/go-enum@latest\n```\n\n### Using GitHub releases\n\nYou can download a pre-built binary from GitHub releases. (Thanks to [GoReleaser](https://github.com/goreleaser/goreleaser-action))\n\n```shell\n# Download the latest release for your platform\ncurl -fsSL \"https://github.com/abice/go-enum/releases/download/v0.9.0/go-enum_$(uname -s)_$(uname -m)\" -o go-enum\nchmod +x go-enum\n\n# Or use a specific version by replacing v0.9.0 with your desired version\n# Example: curl -fsSL \"https://github.com/abice/go-enum/releases/download/v0.8.0/go-enum_$(uname -s)_$(uname -m)\" -o go-enum\n```\n\n### Using Docker\n\nYou can use the Docker image directly without installing anything locally:\n\n```shell\n# Use the latest version\ndocker run -w /app -v $(pwd):/app abice/go-enum:latest\n\n# Or use a specific version\ndocker run -w /app -v $(pwd):/app abice/go-enum:v0.9.0\n```\n\n## Adding it to your project\n\n### Using go generate\n\nFor Go 1.24+ with tool dependency:\n\n1. Install the tool dependency: `go get -tool github.com/abice/go-enum@latest`\n1. Add a go:generate line to your file: `//go:generate go tool go-enum --marshal`\n1. Run go generate: `go generate ./...`\n1. Enjoy your newly created Enumeration!\n\nFor older Go versions:\n\n1. Add a go:generate line to your file: `//go:generate go-enum --marshal`\n1. Run go generate: `go generate ./...`\n1. Enjoy your newly created Enumeration!\n\n### Using Makefile\n\nIf you prefer makefile stuff, you can always do something like this:\n\nFor Go 1.24+ with tool dependency:\n\n```Makefile\nSTANDARD_ENUMS = ./example/animal_enum.go \\\n ./example/color_enum.go\n\nNULLABLE_ENUMS = ./example/sql_enum.go\n\n$(STANDARD_ENUMS): GO_ENUM_FLAGS=--nocase --marshal --names --ptr\n$(NULLABLE_ENUMS): GO_ENUM_FLAGS=--nocase --marshal --names --sqlnullint --ptr\n\nenums: $(STANDARD_ENUMS) $(NULLABLE_ENUMS)\n\n# The generator statement for go enum files using go tool (Go 1.24+)\n%_enum.go: %.go Makefile\n go tool go-enum -f $*.go $(GO_ENUM_FLAGS)\n```\n\nFor older Go versions:\n\n```Makefile\n# The generator statement for go enum files using go-enum binary\n%_enum.go: %.go $(GOENUM) Makefile\n $(GOENUM) -f $*.go $(GO_ENUM_FLAGS)\n```\n\n## Command options\n\n``` shell\ngo-enum --help\n\nNAME:\n   go-enum - An enum generator for go\n\nUSAGE:\n   go-enum [global options]\n\nVERSION:\n   example\n\nGLOBAL OPTIONS:\n   --file value, -f value [ --file value, -f value ]          The file(s) to generate enums.  Use more than one flag for more files. [$GOFILE]\n   --noprefix                                                 Prevents the constants generated from having the Enum as a prefix. (default: false)\n   --lower                                                    Adds lowercase variants of the enum strings for lookup. (default: false)\n   --nocase                                                   Adds case insensitive parsing to the enumeration (forces lower flag). (default: false)\n   --marshal                                                  Adds text (and inherently json) marshalling functions. (default: false)\n   --sql                                                      Adds SQL database scan and value functions. (default: false)\n   --sqlint                                                   Tells the generator that a string typed enum should be stored in sql as an integer value. (default: false)\n   --flag                                                     Adds golang flag functions. (default: false)\n   --jsonpkg value                                            Custom json package for imports instead encoding/json.\n   --prefix value                                             Adds a prefix with a user one. If you would like to replace the prefix, then combine this option with --noprefix.\n   --names                                                    Generates a 'Names() []string' function, and adds the possible enum values in the error response during parsing (default: false)\n   --values                                                   Generates a 'Values() []{{ENUM}}' function. (default: false)\n   --nocamel                                                  Removes the snake_case to CamelCase name changing (default: false)\n   --ptr                                                      Adds a pointer method to get a pointer from const values (default: false)\n   --sqlnullint                                               Adds a Null{{ENUM}} type for marshalling a nullable int value to sql (default: false)\n   --sqlnullstr                                               Adds a Null{{ENUM}} type for marshalling a nullable string value to sql.  If sqlnullint is specified too, it will be Null{{ENUM}}Str (default: false)\n   --template value, -t value [ --template value, -t value ]  Additional template file(s) to generate enums.  Use more than one flag for more files. Templates will be executed in alphabetical order.\n   --alias value, -a value [ --alias value, -a value ]        Adds or replaces aliases for a non alphanumeric value that needs to be accounted for. [Format should be \"key:value,key2:value2\", or specify multiple entries, or both!]\n   --mustparse                                                Adds a Must version of the Parse that will panic on failure. (default: false)\n   --forcelower                                               Forces a camel cased comment to generate lowercased names. (default: false)\n   --forceupper                                               Forces a camel cased comment to generate uppercased names. (default: false)\n   --nocomments                                               Removes auto generated comments.  If you add your own comments, these will still be created. (default: false)\n   --buildtag value, -b value [ --buildtag value, -b value ]  Adds build tags to a generated enum file.\n   --output-suffix .go                                        Changes the default filename suffix of _enum to something else.  .go will be appended to the end of the string no matter what, so that `_test.go` cases can be accommodated\n   --no-iota                                                  Disables the use of iota in generated enums. (default: false)\n   --help, -h                                                 show help\n   --version, -v                                              print the version\n```\n\n### Syntax\n\nThe parser looks for comments on your type defs and parse the enum declarations from it.\nThe parser will look for `ENUM(` and continue to look for comma separated values until it finds a `)`.  You can put values on the same line, or on multiple lines.\\\nIf you need to have a specific value jump in the enum, you can now specify that by adding `=numericValue` to the enum declaration.  Keep in mind, this resets the data for all following values.  So if you specify `50` in the middle of an enum, each value after that will be `51, 52, 53...`\n\n[Examples can be found in the example folder](./example/)\n\n#### Comments\n\nYou can use comments inside enum that start with `//`\\\nThe comment must be at the end of the same line as the comment value, only then it will be added as a comment to the generated constant.\n\n```go\n// Commented is an enumeration of commented values\n/*\nENUM(\nvalue1 // Commented value 1\nvalue2\nvalue3 // Commented value 3\n)\n*/\ntype Commented int\n```\n\nThe generated comments in code will look something like:\n\n```go\n...\nconst (\n    // CommentedValue1 is a Commented of type Value1\n    // Commented value 1\n    CommentedValue1 Commented = iota\n    // CommentedValue2 is a Commented of type Value2\n    CommentedValue2\n    // CommentedValue3 is a Commented of type Value3\n    // Commented value 3\n    CommentedValue3\n)\n...\n```\n\n#### Example\n\nThere are a few examples in the `example` [directory](./example/).\nI've included one here for easy access, but can't guarantee it's up to date.\n\n``` go\n// Color is an enumeration of colors that are allowed.\n/* ENUM(\nBlack, White, Red\nGreen = 33 // Green starts with 33\n*/\n// Blue\n// grey=\n// yellow\n// blue-green\n// red-orange\n// yellow_green\n// red-orange-blue\n// )\ntype Color int32\n```\n\nThe generated code will look something like:\n\n``` go\n// Code generated by go-enum DO NOT EDIT.\n// Version: example\n// Revision: example\n// Build Date: example\n// Built By: example\n\npackage example\n\nimport (\n \"fmt\"\n \"strings\"\n)\n\nconst (\n // ColorBlack is a Color of type Black.\n ColorBlack Color = iota\n // ColorWhite is a Color of type White.\n ColorWhite\n // ColorRed is a Color of type Red.\n ColorRed\n // ColorGreen is a Color of type Green.\n // Green starts with 33\n ColorGreen Color = iota + 30\n // ColorBlue is a Color of type Blue.\n ColorBlue\n // ColorGrey is a Color of type Grey.\n ColorGrey\n // ColorYellow is a Color of type Yellow.\n ColorYellow\n // ColorBlueGreen is a Color of type Blue-Green.\n ColorBlueGreen\n // ColorRedOrange is a Color of type Red-Orange.\n ColorRedOrange\n // ColorYellowGreen is a Color of type Yellow_green.\n ColorYellowGreen\n // ColorRedOrangeBlue is a Color of type Red-Orange-Blue.\n ColorRedOrangeBlue\n)\n\nconst _ColorName = \"BlackWhiteRedGreenBluegreyyellowblue-greenred-orangeyellow_greenred-orange-blue\"\n\nvar _ColorMap = map[Color]string{\n ColorBlack:         _ColorName[0:5],\n ColorWhite:         _ColorName[5:10],\n ColorRed:           _ColorName[10:13],\n ColorGreen:         _ColorName[13:18],\n ColorBlue:          _ColorName[18:22],\n ColorGrey:          _ColorName[22:26],\n ColorYellow:        _ColorName[26:32],\n ColorBlueGreen:     _ColorName[32:42],\n ColorRedOrange:     _ColorName[42:52],\n ColorYellowGreen:   _ColorName[52:64],\n ColorRedOrangeBlue: _ColorName[64:79],\n}\n\n// String implements the Stringer interface.\nfunc (x Color) String() string {\n if str, ok := _ColorMap[x]; ok {\n  return str\n }\n return fmt.Sprintf(\"Color(%d)\", x)\n}\n\nvar _ColorValue = map[string]Color{\n _ColorName[0:5]:                    ColorBlack,\n strings.ToLower(_ColorName[0:5]):   ColorBlack,\n _ColorName[5:10]:                   ColorWhite,\n strings.ToLower(_ColorName[5:10]):  ColorWhite,\n _ColorName[10:13]:                  ColorRed,\n strings.ToLower(_ColorName[10:13]): ColorRed,\n _ColorName[13:18]:                  ColorGreen,\n strings.ToLower(_ColorName[13:18]): ColorGreen,\n _ColorName[18:22]:                  ColorBlue,\n strings.ToLower(_ColorName[18:22]): ColorBlue,\n _ColorName[22:26]:                  ColorGrey,\n strings.ToLower(_ColorName[22:26]): ColorGrey,\n _ColorName[26:32]:                  ColorYellow,\n strings.ToLower(_ColorName[26:32]): ColorYellow,\n _ColorName[32:42]:                  ColorBlueGreen,\n strings.ToLower(_ColorName[32:42]): ColorBlueGreen,\n _ColorName[42:52]:                  ColorRedOrange,\n strings.ToLower(_ColorName[42:52]): ColorRedOrange,\n _ColorName[52:64]:                  ColorYellowGreen,\n strings.ToLower(_ColorName[52:64]): ColorYellowGreen,\n _ColorName[64:79]:                  ColorRedOrangeBlue,\n strings.ToLower(_ColorName[64:79]): ColorRedOrangeBlue,\n}\n\n// ParseColor attempts to convert a string to a Color\nfunc ParseColor(name string) (Color, error) {\n if x, ok := _ColorValue[name]; ok {\n  return x, nil\n }\n return Color(0), fmt.Errorf(\"%s is not a valid Color\", name)\n}\n\nfunc (x Color) Ptr() *Color {\n return \u0026x\n}\n\n// MarshalText implements the text marshaller method\nfunc (x Color) MarshalText() ([]byte, error) {\n return []byte(x.String()), nil\n}\n\n// UnmarshalText implements the text unmarshaller method\nfunc (x *Color) UnmarshalText(text []byte) error {\n name := string(text)\n tmp, err := ParseColor(name)\n if err != nil {\n  return err\n }\n *x = tmp\n return nil\n}\n```\n","funding_links":[],"categories":["Generation and Generics","发电机","代码生成与泛型","Go","Generators","\u003cspan id=\"代和泛型-generation-and-generics\"\u003e代和泛型 Generation and Generics\u003c/span\u003e","Relational Databases"],"sub_categories":["Advanced Console UIs","检索及分析资料库","SQL 查询语句构建库","Search and Analytic Databases","Utility/Miscellaneous","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabice%2Fgo-enum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabice%2Fgo-enum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabice%2Fgo-enum/lists"}