Skip to content

Instantly share code, notes, and snippets.

@slawosz
Created August 14, 2014 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slawosz/1f3d7816f9d087371311 to your computer and use it in GitHub Desktop.
Save slawosz/1f3d7816f9d087371311 to your computer and use it in GitHub Desktop.
go experiments with embedding and interfaces
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