guide: clarify interface binding examples (#141)
This commit is contained in:
@@ -198,21 +198,29 @@ type Fooer interface {
|
|||||||
Foo() string
|
Foo() string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Bar string
|
type MyFooer string
|
||||||
|
|
||||||
func (b *Bar) Foo() string {
|
func (b *MyFooer) Foo() string {
|
||||||
return string(*b)
|
return string(*b)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ProvideBar() *Bar {
|
func provideMyFooer() *MyFooer {
|
||||||
b := new(Bar)
|
b := new(MyFooer)
|
||||||
*b = "Hello, World!"
|
*b = "Hello, World!"
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
var BarFooer = wire.NewSet(
|
type Bar string
|
||||||
ProvideBar,
|
|
||||||
wire.Bind(new(Fooer), new(Bar)))
|
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
|
The first argument to `wire.Bind` is a pointer to a value of the desired
|
||||||
|
|||||||
Reference in New Issue
Block a user