Roger and Jan have given you good answers, but if you want to make use of 
an existing *small *package, check out 

https://github.com/suntong/enum



On Monday, April 15, 2019 at 4:52:52 AM UTC-4, Sankar wrote:
>
> Hi,
>
> I have the following Go type.
>
> ```
> type weekday string
>
> const (
>   Monday weekday = "Monday"
>   Tuesday = "Tuesday"
>   .
>   .
>   .
> )
> ```
>
> Now I have a function that receives a string parameter and I want to 
> evaluate if it s a valid weekday or not. Say:
>
> ```
> func handler(w http.ResponseWriter, r *http.Request) {
>
> // Parse req.body and get a day string
>
> day := "Tuesday" // Valid day
> day := "tuesday" // Invalid day
> day := "123819283" // Invalid day
>
> }
> ```
>
> 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 ?
>
> Thanks.
>

-- 
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.

Reply via email to