Skip to content

Commit 813ed8a

Browse files
committed
experiment: typed enums with interfaces.
Implement typed enums in go by changing the type from `any` to an interface. The interface is defined by a single private method to ensure that exactly one variaent of the enum is populated. We also implement a custom UnmarshalJSON to choose the correct implementation to unmarshal into based on the discriminator field.
1 parent 1866144 commit 813ed8a

File tree

1 file changed

+75
-1
lines changed

1 file changed

+75
-1
lines changed

oxide/types.go

Lines changed: 75 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)