mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 01:21:38 +08:00
fix: coding style and file format for all example.
This commit is contained in:
@@ -1,38 +1,38 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
var i = 5
|
||||
var str = "ABC"
|
||||
|
||||
type Person struct {
|
||||
name string
|
||||
age int
|
||||
}
|
||||
|
||||
type Any interface{}
|
||||
|
||||
func main() {
|
||||
var val Any
|
||||
val = 5
|
||||
fmt.Printf("val has the value: %v\n", val)
|
||||
val = str
|
||||
fmt.Printf("val has the value: %v\n", val)
|
||||
pers1 := new(Person)
|
||||
pers1.name = "Rob Pike"
|
||||
pers1.age = 55
|
||||
val = pers1
|
||||
fmt.Printf("val has the value: %v\n", val)
|
||||
switch t := val.(type) {
|
||||
case int:
|
||||
fmt.Printf("Type int %T\n", t)
|
||||
case string:
|
||||
fmt.Printf("Type string %T\n", t)
|
||||
case bool:
|
||||
fmt.Printf("Type boolean %T\n", t)
|
||||
case *Person:
|
||||
fmt.Printf("Type pointer to Person %T\n", *t)
|
||||
default:
|
||||
fmt.Printf("Unexpected type %T", t)
|
||||
}
|
||||
}
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
var i = 5
|
||||
var str = "ABC"
|
||||
|
||||
type Person struct {
|
||||
name string
|
||||
age int
|
||||
}
|
||||
|
||||
type Any interface{}
|
||||
|
||||
func main() {
|
||||
var val Any
|
||||
val = 5
|
||||
fmt.Printf("val has the value: %v\n", val)
|
||||
val = str
|
||||
fmt.Printf("val has the value: %v\n", val)
|
||||
pers1 := new(Person)
|
||||
pers1.name = "Rob Pike"
|
||||
pers1.age = 55
|
||||
val = pers1
|
||||
fmt.Printf("val has the value: %v\n", val)
|
||||
switch t := val.(type) {
|
||||
case int:
|
||||
fmt.Printf("Type int %T\n", t)
|
||||
case string:
|
||||
fmt.Printf("Type string %T\n", t)
|
||||
case bool:
|
||||
fmt.Printf("Type boolean %T\n", t)
|
||||
case *Person:
|
||||
fmt.Printf("Type pointer to Person %T\n", *t)
|
||||
default:
|
||||
fmt.Printf("Unexpected type %T", t)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user