Skip to content
Skills Library
Programming · Building & coding

go-enum

/go-enum

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.

Repository
hive ↗
Licence
MIT
Last repository change
25.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
1
Deprecation

No signals detected. Repository changed on 25.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

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.

Original author description

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.

How it works

  1. How It Works
  2. Running Generation
  3. Adding a New Enum Value
  4. Adding a New Enum Type
  5. Generated File Naming
  6. Integration with sqlc
  7. Integration with criterio Validation
  8. Gotchas
Original SKILL.md headings · 103 lines, 460 words
SKILL.md preview
---
name: go-enum
description: 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.
compatibility: claude
---

# go-enum in Hive

Hive uses [go-enum](https://github.com/abice/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:

```go
// ItemType categorizes an HC item.
//
// ENUM(epic, task)
type ItemType string
```

go-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) error`
- `ItemTypeValues() []ItemType`
- Constants: `ItemTypeEpic`, `ItemTypeTask`

## Running Generation

After any change to an `// ENUM(...)` comment or adding a new enum type:

```bash
mise run generate:enums    # go-enum only
mise run generate          # all generators (go-enum + sqlc)
```

## Adding a New Enum Value

1. Add the value to the `// ENUM(...)` comment:

```go
// ENUM(epic, task, milestone)
type ItemType string
```

2. Run `mise run generate:enums`.

3. The new constant `ItemTypeMillestone` and `ParseItemType("milestone")` are available.

4. Update any `switch` statements or `OneOf` validators that enumerate values.

## Adding a New Enum Type

1. Create the type with the ENUM comment in the appropriate source file:

```go
// Priority ranks the urgency of an item.
//
// ENUM(low, medium, high, critical)
type Priority string
```

2. Run `mise run generate:enums`. A new `*_enum.go` file is generated next to the source.

3. 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.go`
- `activity.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`:

```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:

```go
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.go` files** — they are overwritten on every generation run.
- **Zero value is not a valid enum.** An unset `ItemType("")` will fail `IsValid()` and `OneOf` checks. Always initialize enum fields.
- **String values match the ENUM comment exactly** (lowercase by default). `ItemTypeEpic` has string value `"epic"`.
- **`mise run generate:enums` sources** are listed in `mise.toml` under `[tasks."generate:enums"]`. If you add a new source file containing an ENUM, add it to the `sources` list so mise detects changes correctly.

Versions

The database has no other skills named go-enum.

Database snapshot: 13.11.2026 · package version 947b63b1b7f5 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100type-bridge-enum-generation
    Generates TypeScript/JavaScript enums from PHP backed enums using the type-bridge:enums Artisan command. Use when user says "generate TS enums", "sync enums to frontend", "type-bridge enums", or needs PHP enum values available in JavaScript/TypeScript.
  • 100type-bridge-enum-translators
    Generates TypeScript/JavaScript translator composables that map PHP enums to their i18n translation keys. Use when user says "generate enum translators", "enum translations for frontend", or needs to display translated enum labels in Vue components.
  • 100enum-struct
    Create, modify, and introspect UserDefinedEnums and UserDefinedStructs (EnumStructService). Use when the user asks to create a Blueprint enum or struct, add enum values or struct members, or inspect an enum/struct's fields. Useful for defining a DataTable row struct.
  • 95ts-conventions
    ACTIVATE when writing TypeScript types, generics, branded types, discriminated unions, or configuring tsconfig. ACTIVATE for 'type vs interface', 'enum alternative', 'branded type', 'satisfies', 'strict mode'. Covers: strict mode policy, no-any/no-enum rules, type over…
  • 100python-scala-enums-adts
    Translating Python enums, dataclasses, and union types to Scala sealed traits, case classes, and ADTs. Use when converting Python Enum classes to Scala enumerations, Python dataclasses to Scala case classes, or Python Union/Optional types to Scala Option/Either/sealed hierarchies.
  • 100metashape-api-lookup
    Look up Metashape Python API parameters and enums from local reference files when building or fixing MCP tools. Use when you need to verify parameter names, types, defaults, or enum values for Metashape API calls.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.