This is a creation in Article, where the information may have evolved or changed.
Look at the source code of Beego today to see such a code
Func Parsebool (Val interface{}) (value bool, err error) {if val! = nil {Switch V: = val. (type) {case Bool:return V, Nilcas E String:switch v {case ' 1 ', ' t ', ' t ', ' true ', ' true ', ' true ', ' yes ', ' yes ', ' yes ', ' y ', ' y ', ' on ', ' on ', ' on ', ' on ', ' on ': return True , nilcase "0", "F", "F", "false", "false", "false", "no", "no", "no", "N", "N", "Off", "off", "Off": return False, Nil}case Int8, Int32, INT64:STRV: = Fmt. Sprintf ("%s", v) if STRV = = "1" {return true, nil} else if Strv = = "0" {return false, nil}case float64:if v = = 1 {return TR UE, NIL} else if V = = 0 {return false, Nil}}return false, FMT. Errorf ("Parsing%q:invalid Syntax", Val)}return false, FMT. Errorf ("parsing <nil>: Invalid Syntax")}
Later I was a little puzzled. This interface type can only be assigned to a variable and then come out with it.
Package Mainimport ("FMT") func main () {//test. Run () test (1)}func Test (Val interface{}) {if val! = Nil {V: = val. (type) FMT. Println (v)}}
directly to the error. Probably mean if you use this. (type) must be placed in the switch.
It seems that my go road is still very long. Play slowly.