Skip to content

Instantly share code, notes, and snippets.

@djmitche
Last active August 29, 2015 14:21
Show Gist options
  • Select an option

  • Save djmitche/b3ffbb9d4b1d79105106 to your computer and use it in GitHub Desktop.

Select an option

Save djmitche/b3ffbb9d4b1d79105106 to your computer and use it in GitHub Desktop.
package main
import "fmt"
type Executer interface {
Show()
}
type executer struct {
b int
}
func (e executer) Show() {
fmt.Printf("Hi, b is %d", e.b)
}
type Moduler interface {
NewRun() Executer
}
type moduler struct {
a int
}
func (m moduler) NewRun() Executer {
return executer{m.a * 10}
}
var current *Moduler
func main() {
current = moduler{7}
run := (*current).NewRun()
run.Show()
}
./pointer.go:32: cannot use moduler literal (type moduler) as type *Moduler in assignment:
*Moduler is pointer to interface, not interface
package main
import "fmt"
type Executer interface {
Show()
}
type executer struct {
b int
}
func (e executer) Show() {
fmt.Printf("Hi, b is %d", e.b)
}
type Moduler interface {
NewRun() Executer
}
type moduler struct {
a int
}
func (m moduler) NewRun() Executer {
return executer{m.a * 10}
}
var current Moduler
func main() {
current = moduler{7}
run := current.NewRun()
run.Show()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment