enumer
go-enum
enumer | go-enum | |
---|---|---|
6 | 7 | |
373 | 656 | |
- | - | |
2.3 | 6.8 | |
3 months ago | about 2 months ago | |
Go | Go | |
GNU General Public License v3.0 or later | MIT License |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
enumer
- Go Enums Still Suck
-
Go isn't the right tool for ANY job
Just use const blocks, iota and enumer and be happy.
-
Does Go not have enums in the sense that I can use them as a type?
Define your type as an alias on int and values using iota as others have said, then autogenerate the rest of the functionality from other languages with https://github.com/dmarkham/enumer
-
Safer Enums in Go
We tried out struct-based enums like this for a while and they're definitely better than the vanilla version, but they still have the problem of "how do you iterate over all the values?" and "how do you create an enum value from a string?". We chanced upon https://github.com/dmarkham/enumer a few months ago and have been very happy so far.
Use enumer in combination with what some of this article.
- What I'd like to see in Go 2.0
go-enum
-
Ten Years of “Go: The Good, the Bad, and the Meh
While not perfect, there are ways to generate enums automatically using go:generate, e.g. https://github.com/abice/go-enum
-
Go vs Rust
I wouldn't write a macro to save a couple of lines, but I would definitely use (not even write, just use) a macro for something like generating enum [de]serialization for both JSON and BSON in one line. Go, even with generics, still has no way of abstracting extremely common patterns like enums without separate generator tools. Clearly someone thought the macro was useful here, but without a macro they had no choice but to write a separate tool.
-
Enums?
Ive found enums in Go are a pain point, especially across an organization because there are many valid ways to implement it. It's also fairly verbose to implement. The way Ive solved for it is code generation. This is a pretty good library that my team uses in production https://github.com/abice/go-enum
-
Why no enums?
I've worked in a few different languages and Go doesn't seem all that unique in the way that it doesn't provide an ENUM primitive. However, I looked around a bit and found go-enum which seems pretty neat. Also, I have no problem writing a custom string or int/iota type. In some cases you want to be able to serialize/deserialize with them -- and in others you don't need that.
-
Does Go not have enums in the sense that I can use them as a type?
Along that same line you can take it a step further and generate the iota block too with this tool https://github.com/abice/go-enum
-
How to do Enums in Go
Looks like this does what you want: https://github.com/abice/go-enum
What are some alternatives?
go-sumtype - A simple utility for running exhaustiveness checks on Go "sum types."
goderive - Derives and generates mundane golang functions that you do not want to maintain yourself
go101 - An up-to-date (unofficial) knowledge base for Go programming self learning
gotype - Golang source code parsing, usage like reflect package
yaegi - Yaegi is Another Elegant Go Interpreter
GoWrap - GoWrap is a command line tool for generating decorators for Go interfaces
go-retry - Go library for retrying with configurable backoffs
go-xray - Helpers for making the use of reflection easier
codegena - Codegeneration tool
generis - Versatile Go code generator.
yaegi-template - Use yaegi as a template engine.
typeregistry - create type dynamically in Golang