Created
August 14, 2014 14:51
-
-
Save slawosz/1f3d7816f9d087371311 to your computer and use it in GitHub Desktop.
go experiments with embedding and interfaces
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" | |
import "encoding/json" | |
type Versions struct { | |
versions []int | |
} | |
func (v Versions) First() int { | |
return v.versions[0] | |
} | |
type Message struct { | |
Name string | |
Body string | |
Time int64 | |
Versions | |
} | |
func (m Message) Foo() { | |
} | |
type Foobable interface { | |
Foo() | |
First() int | |
} | |
func main() { | |
m := Message{"Alice", "Hello", 1294706395881547000, Versions{[]int{111,2,3}}} | |
f := Foobable(m) | |
b, _ := json.Marshal(f) | |
fmt.Println("Hello, playground",string(b)) | |
fmt.Println(f.First()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment