Notice below that foo's bar method has a value receiver and accepts zero arguments. Standard stuff. Where it gets interesting is how I call foo.bar in the example main method.
package main import ( "fmt" ) type foo struct { msg string } func (f foo) bar() string { return f.msg } func main() { receiver := foo{msg: "the value"} result := foo.bar(receiver) fmt.Println(result) }
No comments:
Post a Comment