go_study/bilibili/aceid/struct/kong/test.go

29 lines
451 B
Go

package main
import "fmt"
func myFunc(arg interface{}) {
fmt.Println("myFunc is called...")
fmt.Println(arg)
// interface{}的类型断言
value, ok := arg.(string)
if !ok {
fmt.Println("arg is not string")
} else {
fmt.Println("arg is type, value = ", value)
fmt.Printf("valut type is %T\n", value)
}
}
type Book struct {
auth string
}
func main() {
book := Book{"Golang"}
myFunc(book)
myFunc(100)
myFunc("abc")
myFunc(3.14)
}