FAQ
receive is interface{} type . actually is a point of base type

var value interface{} // hope to get base type not a point of base type

  switch str := receive.(type){
     case *bool:
         value = *str
     case *string:
         value = *str
     case *int:
         value = *str
     case *int64:
         value = *str
     case *uint:
         value = *str
     case *uint64:
         value = *str
     case *float64:
         value = *str
     }
// this is ok, result , value is base type

if i dont use switch, write like this: value = *receive
// this is error

as you see, each case statements is same
any other best method?

btw

can i define bellow command args at the same time
$ ./a -name value
$ ./a subarg -id value

seem the flag Parse and flagset Parse cant run together?


--
君子之交淡若水 --庄子

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

  • Cloud at Jul 28, 2013 at 8:16 am
    switch str := receive.(type)
    if i use this:
    var str interface{}
      switch str := receive.(type)
    this cant work

    it must be use := ?
    which type is str ?
    On Saturday, July 27, 2013, Cloud wrote:

    receive is interface{} type . actually is a point of base type

    var value interface{} // hope to get base type not a point of base type

    switch str := receive.(type){
    case *bool:
    value = *str
    case *string:
    value = *str
    case *int:
    value = *str
    case *int64:
    value = *str
    case *uint:
    value = *str
    case *uint64:
    value = *str
    case *float64:
    value = *str
    }
    // this is ok, result , value is base type

    if i dont use switch, write like this: value = *receive
    // this is error

    as you see, each case statements is same
    any other best method?

    btw

    can i define bellow command args at the same time
    $ ./a -name value
    $ ./a subarg -id value

    seem the flag Parse and flagset Parse cant run together?


    --
    君子之交淡若水 --庄子
    --
    君子之交淡若水 --庄子

    --
    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.
  • Cloud at Jul 28, 2013 at 8:09 am
    switch str := receive.(type)
    if i use this:
    var str interface{}
      switch str = receive.(type) // update for prev mail
    this cant work

    it must be use := ?
    which type is str ?
    On Saturday, July 27, 2013, Cloud wrote:

    switch str := receive.(type)
    if i use this:
    var str interface{}
    switch str := receive.(type)
    this cant work

    it must be use := ?
    which type is str ?
    On Saturday, July 27, 2013, Cloud wrote:

    receive is interface{} type . actually is a point of base type

    var value interface{} // hope to get base type not a point of base type

    switch str := receive.(type){
    case *bool:
    value = *str
    case *string:
    value = *str
    case *int:
    value = *str
    case *int64:
    value = *str
    case *uint:
    value = *str
    case *uint64:
    value = *str
    case *float64:
    value = *str
    }
    // this is ok, result , value is base type

    if i dont use switch, write like this: value = *receive
    // this is error

    as you see, each case statements is same
    any other best method?

    btw

    can i define bellow command args at the same time
    $ ./a -name value
    $ ./a subarg -id value

    seem the flag Parse and flagset Parse cant run together?


    --
    君子之交淡若水 --庄子
    --
    君子之交淡若水 --庄子
    --
    君子之交淡若水 --庄子

    --
    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 Jul 28, 2013 at 9:05 am
    On Fri, Jul 26, 2013 at 6:45 PM, Cloud wrote:

    The language specification is your friend. From
    http://golang.org/ref/spec#Switch_statements

             TypeSwitchGuard = [ identifier ":=" ] PrimaryExpr "." "("
    "type" ")" . // [0]

    If using '=' would be legal, it would imply the LHS identifier must
    have been already declared. If it would have been already declared, it
    must have been declared with exactly one specific type as any other
    "home" (variable, field, parameter, ...). However, it the type switch
    statement, the LHS name has a different type in every type switch
    case[1]. Therefore using '=' in [0] is not permissible.

       [0]: http://golang.org/ref/spec#TypeSwitchGuard
       [1]: http://golang.org/ref/spec#TypeSwitchCase

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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJul 28, '13 at 8:09a
activeJul 28, '13 at 9:05a
posts4
users2
websitegolang.org

2 users in discussion

Cloud: 3 posts Jan Mercl: 1 post

People

Translate

site design / logo © 2022 Grokbase