Skip to content

Instantly share code, notes, and snippets.

@nnao45
Last active September 26, 2018 07:02
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 nnao45/4017af619553cee31734cf89caa0f0c1 to your computer and use it in GitHub Desktop.
Save nnao45/4017af619553cee31734cf89caa0f0c1 to your computer and use it in GitHub Desktop.
golang interface
package main
import (
"fmt"
)
type Animal struct {
Cat string
Dog string
}
func newAnimal() *Animal {
return &Animal {
Cat: "cat",
Dog: "dog",
}
}
type Count interface {
One() string
Two() string
}
func(a Animal) One() string{
return "one"
}
func(a Animal) Two() string{
return "two"
}
func main() {
a := newAnimal()
c := Count(a)
fmt.Println(a.Cat)
fmt.Println(a.Dog)
fmt.Println(c.One())
fmt.Println(c.Tow())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment