FAQ
I have the need to validate that a configuration data value is in
a enumerated list of string values. The enumerated list is static at
compile time.

I can do this with an array or slice but I'm wondering is there a more
idoimatic way to do this. I will have several different lists of strings
to manage.

http://play.golang.org/p/IrXo-i5hB_

Thanks

Eric

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Rémy Oudompheng at Jun 24, 2013 at 9:09 pm

    2013/6/24 Eric Palmer <eric@ericfpalmer.com>:
    I have the need to validate that a configuration data value is in a
    enumerated list of string values. The enumerated list is static at compile
    time.

    I can do this with an array or slice but I'm wondering is there a more
    idoimatic way to do this. I will have several different lists of strings to
    manage.

    http://play.golang.org/p/IrXo-i5hB_

    Use a switch:

    switch value {
    case "valid1", "valid2", "valid3":
         return true
    default:
         return false
    }

    Rémy.

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Eric Palmer at Jun 24, 2013 at 9:14 pm
    Thanks

    Duh!!!!

    Eric


    On Mon, Jun 24, 2013 at 5:09 PM, Rémy Oudompheng
    wrote:
    2013/6/24 Eric Palmer <eric@ericfpalmer.com>:
    I have the need to validate that a configuration data value is in a
    enumerated list of string values. The enumerated list is static at compile
    time.

    I can do this with an array or slice but I'm wondering is there a more
    idoimatic way to do this. I will have several different lists of
    strings to
    manage.

    http://play.golang.org/p/IrXo-i5hB_

    Use a switch:

    switch value {
    case "valid1", "valid2", "valid3":
    return true
    default:
    return false
    }

    Rémy.


    --
    KK4MWM (Ham Radio)
    About Me <http://about.me/ericpalmer>
    http://www.thingiverse.com/DaddyOh
    Join the 3DPrinter Revolution
    http://makerbot.com

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jan Mercl at Jun 25, 2013 at 6:32 am

    On Mon, Jun 24, 2013 at 11:09 PM, Rémy Oudompheng wrote:
    case "valid1", "valid2", "valid3":
    return true
    It would be fun (and performant) to have the compiler generate a DFA
    for this ;-)

    -j

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Ethan Burns at Jun 25, 2013 at 4:25 pm
    I like using maps for this type of
    thing: http://play.golang.org/p/naZ18QLAp-
    On Monday, June 24, 2013 5:07:05 PM UTC-4, Eric Palmer wrote:

    I have the need to validate that a configuration data value is in
    a enumerated list of string values. The enumerated list is static at
    compile time.

    I can do this with an array or slice but I'm wondering is there a more
    idoimatic way to do this. I will have several different lists of strings
    to manage.

    http://play.golang.org/p/IrXo-i5hB_

    Thanks

    Eric
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJun 24, '13 at 9:07p
activeJun 25, '13 at 4:25p
posts5
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase