Twice a year, we run an online training where you can learn Go Event-Driven. The time has come! Learn more.

Available until 26 April

Posts List

Safer Enums in Go

Safer Enums in Go

Enums are a crucial part of web applications. Go doesn’t support them out of the box, but there are ways to emulate them. Many obvious solutions are far from ideal. Here are some ideas we use that make enums safer by design. iota Go lets you enumerate things with iota. const ( Guest = iota Member Moderator Admin ) Full source: github.com/ThreeDotsLabs/go-web-app-antipatterns/02-enums/01-iota/role/role.go While Go is explicit, iota seems relatively obscure.



Share on Hacker News
Share on Reddit

Do you like our posts and you are still not subscribed to our newsletter? We are not sending any spam - just notifications about new content.