Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@quxiao
Last active February 15, 2017 08:58
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 quxiao/e792c3d8af6f61d714e79d365b272981 to your computer and use it in GitHub Desktop.
Save quxiao/e792c3d8af6f61d714e79d365b272981 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
type Inter interface {
Func(string)
}
type Impl struct {
count int
}
func (p *Impl) Func(s string) {
p.count += 1
fmt.Println(s)
return
}
type Service struct {
handlers []Inter
}
func (p *Service) AppendHandler(i Inter) {
p.handlers = append(p.handlers, i)
}
func (p *Service) Run() {
for _, handler := range p.handlers {
handler.Func("string")
}
}
func main() {
var (
service Service
impl Impl
)
service.AppendHandler(impl)
service.Run()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment