Skip to content

Instantly share code, notes, and snippets.

@bonifaido
Last active May 29, 2018 14:59
Show Gist options
  • Save bonifaido/cf966d2c41521ef95fcdd541b04c0c46 to your computer and use it in GitHub Desktop.
Save bonifaido/cf966d2c41521ef95fcdd541b04c0c46 to your computer and use it in GitHub Desktop.
Difference between taking something by value or by pointer in Go
&main.Something{}
(*interface {})(0xc42000e1e0)
package main
import "fmt"
type Something struct{}
func receiverByPointer(p interface{}) {
fmt.Printf("%#v\n", p)
}
func receiverByValue(p interface{}) {
fmt.Printf("%#v\n", &p)
}
func main() {
receiverByPointer(&Something{})
receiverByValue(Something{})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment