Created
September 23, 2014 13:17
-
-
Save slawosz/ed427b83fe7501d67c15 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type Foo struct { | |
Payload string | |
} | |
type Bar struct { | |
Foo | |
} | |
func (f *Foo) DoStuff(arg string) { | |
f.Payload = arg | |
} | |
func main() { | |
f := &Bar{Foo{"1234"}} | |
f.DoStuff("4321") | |
fmt.Println(f) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func call(f func(string)) { f("foo") } | |
type Foo struct { | |
Payload string | |
} | |
func (f Foo) foo(str string) { | |
fmt.Println(f.Payload, str) | |
} | |
func main() { | |
f1 := Foo{"foo1"} | |
f2 := Foo{"foo2"} | |
call(f1.foo) | |
call(f2.foo) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment