Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,25 @@ The tool generates the following for your type:

Since Go structs cannot be `const`, these enums are defined as `var`. While technically mutable, the convention is to treat them as immutable constants.

### Immutability with Private Fields

To more strictly enforce immutability, the recommended pattern is to use **private fields** in your struct definition and expose data via **public getter methods**.

```go
//enumr:Free Price:0.0
//enumr:Pro Price:29.99
type Plan struct {
price float64 // private field
}

// Public getter prevents external modification
func (p Plan) Price() float64 {
return p.price
}
```

This ensures that consumers of your package can read the data but cannot modify the enum fields directly.

## Inspiration

This project is inspired by the excellent work of:
Expand Down