In go I can use stringer to convert const names to string:
//go:generate stringer -type=M
type M int
const (
_ M = iota
Foo // "Foo"
Bar // "Bar"
)
Is there anything that would allow me to convert the "foo" string into a variable of type M except for a hand-written switch?
I've recently discovered https://github.com/alvaroloes/enumer which adds a TypeString(string) Type method that will convert string value to type and can replace stringer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With