Skip to content

Instantly share code, notes, and snippets.

@r002
Created June 8, 2021 17:22
Show Gist options
  • Save r002/248b7a4915b8991feb4a0fa6d22b20ee to your computer and use it in GitHub Desktop.
Save r002/248b7a4915b8991feb4a0fa6d22b20ee to your computer and use it in GitHub Desktop.
Go Tutorial: Slice example - Always passed by reference
func TestHello(t *testing.T) {
fmt.Println(">> Slice example - Always passed by reference")
testcase1 := []struct {
arg string
want string
}{
{"original arg val", "original want val"},
}
fmt.Println(">> testcase1.arg:", testcase1[0].arg)
testcase2 := testcase1
testcase1[0].arg = "changed arg val"
fmt.Println(">> testcase2.arg:", testcase2[0].arg)
}
// Output:
>> Slice example - Always passed by reference
>> testcase1.arg: original arg val
>> testcase2.arg: changed arg val
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment