Skip to content

Instantly share code, notes, and snippets.

@polidog
Last active September 1, 2017 14:18
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 polidog/f0906f821afca6652e3d32613b91ddcb to your computer and use it in GitHub Desktop.
Save polidog/f0906f821afca6652e3d32613b91ddcb to your computer and use it in GitHub Desktop.
interface+pointer sample
package main
import (
"fmt"
)
type Hoge interface {
Flush()
}
type Fuga struct {
Count int
}
func (f *Fuga) Flush() {
f.Count++
fmt.Println("flush: ", f.Count)
}
func (f Fuga) DisplayCount() {
fmt.Println("count: ", f.Count)
}
func Call(h Hoge) {
h.Flush()
}
func Call2(f Fuga) {
f.Flush()
}
func main() {
f := &Fuga{}
Call(f)
Call(f)
Call(f)
Call2(*f)
f.DisplayCount()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment