go version go1.7.1 darwin/amd64
Tried to declare enums in my package.
That there would be some mechanism to declare enums types.
That there was no native way to declare enum types in Go lang instead I saw some weird hacks to make things work barely.
Why is there no native way to declare enum types in Go lang, it is such a useful and convenient feature.
Here are enums in HackLang for example.
It would be really nice to have something like:
enum HTTP struct {
GET string "GET"
POST "POST"
DELETE "DELETE"
PUT "PUT"
}
Hi! The Go project does not uses the github issue tracker for asking questions. In fact, there is no "What is you question?" header in the issue template.
See the Questions wiki page for a list of places where you could ask about enums.
type HTTP string
const (
GET = HTTP("GET")
POST = HTTP("POST")
DELETE = HTTP("DELETE")
PUT = HTTP("PUT")
)
@stemar94 But you can't use this to verify type, e.g. in Type struct:
type Request struct {
Method HTTP `json:"method"`
}
It will not make sure that values are one of the consts. Any ideas?
Yeah, let's discuss this on the mailing list or Slack instead. See https://golang.org/wiki/Questions
Most helpful comment