From 58e5de342ae1286a6e20c4f674e96b8413e29325 Mon Sep 17 00:00:00 2001 From: shantuo Date: Fri, 1 Mar 2019 11:28:55 -0800 Subject: [PATCH] guide: clarify interface binding examples (#141) --- docs/guide.md | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/docs/guide.md b/docs/guide.md index 35589d0..f493f55 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -198,21 +198,29 @@ type Fooer interface { Foo() string } -type Bar string +type MyFooer string -func (b *Bar) Foo() string { +func (b *MyFooer) Foo() string { return string(*b) } -func ProvideBar() *Bar { - b := new(Bar) +func provideMyFooer() *MyFooer { + b := new(MyFooer) *b = "Hello, World!" return b } -var BarFooer = wire.NewSet( - ProvideBar, - wire.Bind(new(Fooer), new(Bar))) +type Bar string + +func provideBar(f Fooer) string { + // f will be a *MyFooer. + return f.Foo() +} + +var Set = wire.NewSet( + provideMyFooer, + wire.Bind((*Fooer)(nil), (*MyFooer)(nil)), + provideBar) ``` The first argument to `wire.Bind` is a pointer to a value of the desired