On Mon, Apr 15, 2019 at 10:53 AM Sankar <sankar.curios...@gmail.com> wrote:
> I want to evaluate if the string variable `day` is one of the valid permitted values for the [Ww]eekday custom type. What is the recommended / right go way of doing this ? Go has no enums and type weekday has no permitted/not permitted values. You have to check for valid values manually. Sometimes using a map is a good approach, sometimes a switch may be more appropriate. For numeric intervals an if statement will work best so sometimes it's better to have symbolic names for the permitted values and use the stringer utility to attach a String() method to them. type Weekday int // or perhaps uint const ( Monday Weekday = iota Tuiesday Wednesday ... Sunday ) -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.