goose: add interface binding
An interface binding instructs goose that a concrete type should be used to satisfy a dependency on an interface type. goose could determine this implicitly, but having an explicit directive makes the provider author's intent clear and allows different concrete types to satisfy different smaller interfaces. Reviewed-by: Tuo Shan <shantuo@google.com>
This commit is contained in:
26
internal/goose/testdata/ImportedInterfaceBinding/bar/bar.go
vendored
Normal file
26
internal/goose/testdata/ImportedInterfaceBinding/bar/bar.go
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
_ "foo"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println(injectFooer().Foo())
|
||||
}
|
||||
|
||||
type Bar string
|
||||
|
||||
func (b *Bar) Foo() string {
|
||||
return string(*b)
|
||||
}
|
||||
|
||||
//goose:provide
|
||||
func provideBar() *Bar {
|
||||
b := new(Bar)
|
||||
*b = "Hello, World!"
|
||||
return b
|
||||
}
|
||||
|
||||
//goose:bind provideBar "foo".Fooer *Bar
|
||||
9
internal/goose/testdata/ImportedInterfaceBinding/bar/goose.go
vendored
Normal file
9
internal/goose/testdata/ImportedInterfaceBinding/bar/goose.go
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
//+build gooseinject
|
||||
|
||||
package main
|
||||
|
||||
import "foo"
|
||||
|
||||
//goose:use provideBar
|
||||
|
||||
func injectFooer() foo.Fooer
|
||||
Reference in New Issue
Block a user