package main import ( "fmt" "reflect" ) func testFunc(value interface{}) { fmt.Println("---------------------") fmt.Println("type = " + reflect.ValueOf(value).Type().String()) fmt.Println("kind = " + reflect.ValueOf(value).Kind().String()) if reflect.ValueOf(value).Kind()==reflect.Ptr { fmt.Println("--> pointer " ) pointsToValue := reflect.Indirect( reflect.ValueOf(value)) fmt.Println("-->",pointsToValue.Kind(), " - ",pointsToValue.Type(), " - ", pointsToValue) if pointsToValue.Kind()==reflect.Slice { fmt.Println("--> slice !! " ) } } } func main() { var testVar1 string var testVar2 []string var testVar3 []*string
testVar2 = append(testVar2,"A") testVar2 = append(testVar2,"B")
testFunc(testVar1) testFunc(&testVar1)
testFunc(testVar2) testFunc(&testVar2)
testFunc(testVar3) testFunc(&testVar3) }
https://play.golang.org/p/1PEOYIPdyFb
댓글 없음:
댓글 쓰기