proposal: spec: add typed enum support
I'd like to propose that enum be added to Go as a special kind of `type`. The examples below are borrowed from the protobuf example. ### Enums in Go today ``` type SearchRequest int var ( SearchRequestUNIVERSAL SearchRequest = 0 // UNIVERSAL SearchRequestWEB SearchRequest = 1 // WEB SearchRequestIMAGES SearchRequest = 2 // IMAGES SearchRequestLOCAL SearchRequest = 3 // LOCAL SearchRequestNEWS SearchRequest = 4 // NEWS SearchRequestPRODUCTS SearchRequest = 5 // PRODUCTS SearchRequestVIDEO SearchRequest = 6 // VIDEO ) type SearchRequest string var ( SearchRequestUNIVERSAL SearchRequest = "UNIVERSAL" SearchRequestWEB SearchRequest = "WEB" SearchRequestIMAGES SearchRequest = "IMAGES" SearchRequestLOCAL SearchRequest = "LOCAL" SearchRequestNEWS SearchRequest = "NEWS" SearchRequestPRODUCTS SearchRequest = "PRODUCTS" SearchRequestVIDEO SearchRequest = "VIDEO" ) // IsValid has to be called everywhere input happens, or you risk bad data - no guarantees func (sr SearchRequest) IsValid() bool { switch sr { case SearchRequestUNIVERSAL, SearchRequestWEB...: return true } return false } ``` ### How it might look with language support ``` enum SearchRequest int { 0 // UNIVERSAL 1 // WEB 2 // IMAGES 3 // LOCAL 4 // NEWS 5 // PRODUCTS 6 // VIDEO } enum SearchRequest string { "UNIVERSAL" "WEB" "IMAGES" "LOCAL" "NEWS" "PRODUCTS" "VIDEO" } ``` The pattern is common en
Posted by derekperkins on Mar 31, 2017, 11:07 PM
Tags
Related issues
- some bike vendor told me that the biggest problem with regular to ebike conversion was that regular bike frames were not strong enough to...
- I think of this as the kiosk economy.
- What a goofy comment.
- There's lots of evidence for positive influences of Caffeine on the body (some negative as well), especially the brain.
- Compose support in WSLc
- [RFC] Roadmap to v2.0
Raise real-world problems, find people facing the same issue, and discuss solutions.4,500 issues0 comments
support (Other)
some bike vendor told me that the biggest problem with regular to ebike conversion was that regular bike frames were not strong enough to...
I think of this as the kiosk economy.
What a goofy comment.
There's lots of evidence for positive influences of Caffeine on the body (some negative as well), especially the brain.
Compose support in WSLc
[RFC] Roadmap to v2.0
[Feature]: Add TurboQuant Support for KV Cache Quantization
Support for AGENTS.md and .agents/skills/, the community has been asking since August 2025
proposal: spec: add typed enum support
I'd like to propose that enum be added to Go as a special kind of `type`. The examples below are borrowed from the protobuf example. ### Enums in Go today ``` type SearchRequest int var ( SearchRequestUNIVERSAL SearchRequest = 0 // UNIVERSAL SearchRequestWEB SearchRequest = 1 // WEB SearchRequestIMAGES SearchRequest = 2 // IMAGES SearchRequestLOCAL SearchRequest = 3 // LOCAL SearchRequestNEWS SearchRequest = 4 // NEWS SearchRequestPRODUCTS SearchRequest = 5 // PRODUCTS SearchRequestVIDEO SearchRequest = 6 // VIDEO ) type SearchRequest string var ( SearchRequestUNIVERSAL SearchRequest = "UNIVERSAL" SearchRequestWEB SearchRequest = "WEB" SearchRequestIMAGES SearchRequest = "IMAGES" SearchRequestLOCAL SearchRequest = "LOCAL" SearchRequestNEWS SearchRequest = "NEWS" SearchRequestPRODUCTS SearchRequest = "PRODUCTS" SearchRequestVIDEO SearchRequest = "VIDEO" ) // IsValid has to be called everywhere input happens, or you risk bad data - no guarantees func (sr SearchRequest) IsValid() bool { switch sr { case SearchRequestUNIVERSAL, SearchRequestWEB...: return true } return false } ``` ### How it might look with language support ``` enum SearchRequest int { 0 // UNIVERSAL 1 // WEB 2 // IMAGES 3 // LOCAL 4 // NEWS 5 // PRODUCTS 6 // VIDEO } enum SearchRequest string { "UNIVERSAL" "WEB" "IMAGES" "LOCAL" "NEWS" "PRODUCTS" "VIDEO" } ``` The pattern is common en
Comments (0)
No comments yet. Start the discussion.