Skip to content

Instantly share code, notes, and snippets.

@aquilax
Created February 26, 2012 17:50
Show Gist options
  • Save aquilax/1917943 to your computer and use it in GitHub Desktop.
Save aquilax/1917943 to your computer and use it in GitHub Desktop.
Go Interface working sample
package main
import (
"fmt"
)
type Common struct {
s string
}
type Object interface {
GetCommon() (*Common)
}
type Test struct{
c *Common
}
func (t *Test) GetCommon() (*Common) {
return t.c
}
func Show(o Object) {
fmt.Println(o.GetCommon().s)
}
func NewCommon(text string) (*Common){
return &Common{text}
}
func main(){
c := NewCommon("test")
t := Test{c}
Show(&t)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment