From d6a1cbd47ffcd711b1bf70624a23ca349889b8c9 Mon Sep 17 00:00:00 2001 From: Bruce Date: Mon, 24 Sep 2018 09:12:35 +0800 Subject: [PATCH] play adress --- playground/basic/address_test.go | 40 ++++++++++++++++++++++++++++++++ playground/http/upload_test.go | 3 ++- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 playground/basic/address_test.go diff --git a/playground/basic/address_test.go b/playground/basic/address_test.go new file mode 100644 index 0000000..435c9d9 --- /dev/null +++ b/playground/basic/address_test.go @@ -0,0 +1,40 @@ +package basic + +import ( + "fmt" + "testing" +) + +func TestPrintAddress(t *testing.T) { + var a int + fmt.Printf("%T, %v, %p \n", a, a, &a) + passByVariable(a) + passByPointer(&a) +} + +func passByVariable(a int) { + fmt.Printf("%T, %v, %p \n", a, a, &a) +} + +func passByPointer(a *int) { + fmt.Printf("%T, %v, %p \n", a, a, &a) + fmt.Printf("%T, %v, %p \n", *a, *a, &*a) +} + +type robot struct{} + +func TestStructAddress(t *testing.T) { + var a robot + fmt.Printf("%T, %v, %p \n", a, a, &a) + passStructByVariable(a) + passStructByPointer(&a) +} + +func passStructByVariable(a robot) { + fmt.Printf("%T, %v, %p \n", a, a, &a) +} + +func passStructByPointer(a *robot) { + fmt.Printf("%T, %v, %p \n", a, a, &a) + fmt.Printf("%T, %v, %p \n", *a, *a, &*a) +} diff --git a/playground/http/upload_test.go b/playground/http/upload_test.go index 180c032..0081e10 100644 --- a/playground/http/upload_test.go +++ b/playground/http/upload_test.go @@ -30,7 +30,8 @@ func TestUploadFormFile(t *testing.T) { if err != nil { t.Fatal(err) } - if _, err = io.Copy(formFileWriter, bytes.NewReader(yamlFile)); err != nil { + _, err = io.Copy(formFileWriter, bytes.NewReader(yamlFile)) + if err != nil { t.Fatal(err) } writer.Close()