Last active
February 15, 2017 08:58
-
-
Save quxiao/e792c3d8af6f61d714e79d365b272981 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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