go-enum
Skill41 starsChanged 7 days agoMITView on GitHub
Define and extend Go enums using the go-enum code generator. Use when adding new enum types, extending existing ones, or running generation after changes.
In this repository17 other files it gives its agents.
- AGENTS.mdAGENTS.md
- docs/AGENTS.mdAGENTS.md
- cli-autocalibrateSkill
- cli-smokeSkill
- cli-tuiSkill
- desktop-apiSkill
- desktop-commands-auditSkill
- desktop-devserverSkill
- desktop-shipped-skillsSkill
- desktop-ui-auditSkill
- desktop-ui-perfSkill
- docs-auditSkill
- docs-pageSkill
- release-notesSkill
- release-prepSkill
- releaseSkill
- sqlcSkill
The file
We split this skill into the rules it gives an agent
10 rules. About 0 are common, 2 are distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 33
After any change to an // ENUM(...) comment or adding a new enum type:
- Very specific: line 42
Add the value to the // ENUM(...) comment:
- Very specific: line 53
Update any switch statements or OneOf validators that enumerate values.
- Distinctive: line 57
Create the type with the ENUM comment in the appropriate source file:
- Very specific: line 66
Run mise run generate:enums.
- Distinctive: line 68
Never define the constants manually — the generator owns them.
- Very specific: line 76
If a source file defines multiple enum types, all are generated into the same _enum.go file.
- Very specific: line 80
When a column stores an enum, the generated go-enum type satisfies driver.Valuer/sql.Scanner via its MarshalText/UnmarshalText methods.
- Very specific: line 94
Use criterio.OneOf(...) to validate enum fields, listing all valid constants explicitly:
- Very specific: line 100
Do not call i.Type.IsValid() inside criterio — OneOf is more readable and produces better error messages.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
go-enum in Hive
Hive uses go-enum to generate enum methods from // ENUM(...) comments. Generated files are committed — never edit them manually.
How It Works
Define an enum type with a special comment:
// ItemType categorizes an HC item.
//
// ENUM(epic, task)
type ItemType stringgo-enum reads the comment and generates item_enum.go (or the file named after the type's source file with _enum suffix) containing:
ParseItemType(s string) (ItemType, error)(t ItemType) IsValid() bool(t ItemType) String() string(t ItemType) MarshalText() ([]byte, error)/UnmarshalText([]byte) errorItemTypeValues() []ItemType- Constants:
ItemTypeEpic,ItemTypeTask
Running Generation
After any change to an // ENUM(...) comment or adding a new enum type:
mise run generate:enums # go-enum only
mise run generate # all generators (go-enum + sqlc)Adding a New Enum Value
- Add the value to the
// ENUM(...)comment:
// ENUM(epic, task, milestone)
type ItemType string- Run
mise run generate:enums. - The new constant
ItemTypeMillestoneandParseItemType("milestone")are available. - Update any
switchstatements orOneOfvalidators that enumerate values.
Adding a New Enum Type
- Create the type with the ENUM comment in the appropriate source file:
// Priority ranks the urgency of an item.
//
// ENUM(low, medium, high, critical)
type Priority string- Run
mise run generate:enums. A new*_enum.gofile is generated next to the source. - Never define the constants manually — the generator owns them.
Generated File Naming
go-enum creates files named <source_file_stem>_enum.go. Examples:
item.go→item_enum.goactivity.go→activity_enum.go
If a source file defines multiple enum types, all are generated into the same _enum.go file.
Integration with sqlc
When a column stores an enum, the generated go-enum type satisfies driver.Valuer/sql.Scanner via its MarshalText/UnmarshalText methods. Add an override to sqlc.yaml:
overrides:
- column: "hc_items.type"
go_type:
import: "github.com/colonyops/hive/internal/domain/hc"
type: "ItemType"This lets sqlc use hc.ItemType directly in generated query params/returns — no string conversion needed in the store layer.
Integration with criterio Validation
Use criterio.OneOf(...) to validate enum fields, listing all valid constants explicitly:
criterio.Run("type", i.Type, criterio.OneOf(ItemTypeEpic, ItemTypeTask))Do not call i.Type.IsValid() inside criterio — OneOf is more readable and produces better error messages.
Gotchas
- Never edit
*_enum.gofiles — they are overwritten on every generation run. - Zero value is not a valid enum. An unset
ItemType("")will failIsValid()andOneOfchecks. Always initialize enum fields. - String values match the ENUM comment exactly (lowercase by default).
ItemTypeEpichas string value"epic". mise run generate:enumssources are listed inmise.tomlunder[tasks."generate:enums"]. If you add a new source file containing an ENUM, add it to thesourceslist so mise detects changes correctly.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

