[lectures/02-interfaces] Update type switch slide.
This commit is contained in:
parent
e09f4dc6b8
commit
72f428d81c
1 changed files with 5 additions and 5 deletions
|
@ -376,20 +376,20 @@ Check type
|
||||||
* Type switch
|
* Type switch
|
||||||
|
|
||||||
func sqlQuote(x interface{}) string {
|
func sqlQuote(x interface{}) string {
|
||||||
switch x := x.(type) {
|
switch v := x.(type) {
|
||||||
case nil:
|
case nil:
|
||||||
return "NULL"
|
return "NULL"
|
||||||
case int, uint:
|
case int, uint:
|
||||||
return fmt.Sprintf("%d", x) // x has type interface{} here.
|
return fmt.Sprintf("%d", v) // v has type interface{} here.
|
||||||
case bool:
|
case bool:
|
||||||
if x {
|
if v {
|
||||||
return "TRUE"
|
return "TRUE"
|
||||||
}
|
}
|
||||||
return "FALSE"
|
return "FALSE"
|
||||||
case string:
|
case string:
|
||||||
return sqlQuoteString(x) // (not shown)
|
return sqlQuoteString(v) // (not shown)
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("unexpected type %T: %v", x, x))
|
panic(fmt.Sprintf("unexpected type %T: %v", v, v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue