Skip to content

Commit

Permalink
Iota example (#23)
Browse files Browse the repository at this point in the history
* iota

* iota-example

* clean
  • Loading branch information
nikolaydubina authored May 28, 2024
1 parent ca4004a commit 6055f6d
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ var (
)
```

It also works with raw `iota` enums:

```go
type Size uint8

//go:generate go-enum-encoding -type=Size
const (
UndefinedSize Size = iota // json:""
Small // json:"small"
Large // json:"large"
XLarge // json:"xlarge"
)
```

## Related Work and References

- http://github.com/zarldev/goenums - does much more advanced struct generation, generates all enum utilities besides encoding, does not generate tests, uses similar notation to trigger go:generate but with different comment directives (non-json field tags)
Expand Down
11 changes: 11 additions & 0 deletions internal/testdata/size.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package color

type Size uint8

//go:generate go-enum-encoding -type=Size
const (
UndefinedSize Size = iota // json:""
Small // json:"small"
Large // json:"large"
XLarge // json:"xlarge"
)
39 changes: 39 additions & 0 deletions internal/testdata/size_enum_encoding.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions internal/testdata/size_enum_encoding_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6055f6d

Please sign in to comment.