0

I'd like to create an enumeration (constants) with mutliple constant types for the values.

package startup

type args string
type argsOptional string

const (
    HELP args = "help" argsOptional = "h"
    ABOUT args = "about"
)

How'd I do it? I cannot use any array as constant, so I am confused how it would be best to do it.

Defining an const array like it's mentioned in the duplicate answer is not working and still not what I want!:

type args = [...]string

const (
    HELP args = [2]string {"help","h"}
)

Does not compile!

Pwnstar
  • 2,333
  • 2
  • 29
  • 52
  • There is no real support for enums in go.[See previous StackOverflow answer.](https://stackoverflow.com/a/14426447/9478968) –  Mar 12 '18 at 10:40
  • Yeah that's what I know, too. But I want to define a constant, with some private values, like an enumeration would do. – Pwnstar Mar 12 '18 at 11:34
  • 1
    Don't use a const, or don't use Go, or use something in between, for example: https://play.golang.org/p/ZM6to5DFOGB. Basically the language does not provide what you so desire, so saying "I want X" if Go does not provide X is not gonna get you anywhere. Also, Go is open source so if you feel up to it, fork it and you can add the desired features yourself. – mkopriva Mar 12 '18 at 12:26
  • ... or https://play.golang.org/p/LQy066ICpCU – mkopriva Mar 12 '18 at 12:38
  • 1
    Guys marked this question a duplicate, though I believe you're more trying to find a concise and elegant solution for representing your idea, not exactly sticking to consts. If so, please see https://play.golang.org/p/arx_Ew5-Eja with structs or https://play.golang.org/p/UBFDcRc1j54 with slices. – Wojciech Kaczmarek Mar 12 '18 at 15:34
  • I'll give it a try. – Pwnstar Mar 13 '18 at 08:28

0 Answers0