Skip to content

Instantly share code, notes, and snippets.

@baijum
Created June 27, 2019 09:35
Show Gist options
  • Select an option

  • Save baijum/820945718e94c336cb96387b246a4bc8 to your computer and use it in GitHub Desktop.

Select an option

Save baijum/820945718e94c336cb96387b246a4bc8 to your computer and use it in GitHub Desktop.
interface implements
package main
import "fmt"
type myInterace interface {
Hello() string
}
type myStruct struct{}
func (m myStruct) Hello() string {
return "Hello 1"
}
func say(mi myInterace) {
fmt.Println(mi.Hello())
}
var _ myInterace = myStruct{}
type newStruct struct{}
var _ myInterace = newStruct{}
func main() {
m1 := myStruct{}
say(m1)
/*
n1 := newStruct{}
say(n1)
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment