@@ -92,8 +92,8 @@ func generateInjectors(g *gen, pkgInfo *loader.PackageInfo) (injectorFiles []*as
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
useCall := isInjector(&pkgInfo.Info, fn)
|
||||
if useCall == nil {
|
||||
buildCall := isInjector(&pkgInfo.Info, fn)
|
||||
if buildCall == nil {
|
||||
continue
|
||||
}
|
||||
if len(injectorFiles) == 0 || injectorFiles[len(injectorFiles)-1] != f {
|
||||
@@ -103,7 +103,7 @@ func generateInjectors(g *gen, pkgInfo *loader.PackageInfo) (injectorFiles []*as
|
||||
g.p("// Injectors from %s:\n\n", name)
|
||||
injectorFiles = append(injectorFiles, f)
|
||||
}
|
||||
set, err := oc.processNewSet(pkgInfo, useCall)
|
||||
set, err := oc.processNewSet(pkgInfo, buildCall)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%v: %v", g.prog.Fset.Position(fn.Pos()), err)
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ import (
|
||||
// A ProviderSet describes a set of providers. The zero value is an empty
|
||||
// ProviderSet.
|
||||
type ProviderSet struct {
|
||||
// Pos is the position of the call to goose.NewSet or goose.Use that
|
||||
// Pos is the position of the call to goose.NewSet or goose.Build that
|
||||
// created the set.
|
||||
Pos token.Pos
|
||||
// PkgPath is the import path of the package that declared this set.
|
||||
@@ -316,7 +316,7 @@ type structProviderPair struct {
|
||||
}
|
||||
|
||||
func (oc *objectCache) processNewSet(pkg *loader.PackageInfo, call *ast.CallExpr) (*ProviderSet, error) {
|
||||
// Assumes that call.Fun is goose.NewSet or goose.Use.
|
||||
// Assumes that call.Fun is goose.NewSet or goose.Build.
|
||||
|
||||
pset := &ProviderSet{
|
||||
Pos: call.Pos(),
|
||||
@@ -558,7 +558,7 @@ func processValue(fset *token.FileSet, info *types.Info, call *ast.CallExpr) (*V
|
||||
}
|
||||
|
||||
// isInjector checks whether a given function declaration is an
|
||||
// injector template, returning the goose.Use call. It returns nil if
|
||||
// injector template, returning the goose.Build call. It returns nil if
|
||||
// the function is not an injector template.
|
||||
func isInjector(info *types.Info, fn *ast.FuncDecl) *ast.CallExpr {
|
||||
if fn.Body == nil {
|
||||
@@ -595,15 +595,15 @@ func isInjector(info *types.Info, fn *ast.FuncDecl) *ast.CallExpr {
|
||||
if len(panicCall.Args) != 1 {
|
||||
return nil
|
||||
}
|
||||
useCall, ok := panicCall.Args[0].(*ast.CallExpr)
|
||||
buildCall, ok := panicCall.Args[0].(*ast.CallExpr)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
useObj := qualifiedIdentObject(info, useCall.Fun)
|
||||
if !isGooseImport(useObj.Pkg().Path()) || useObj.Name() != "Use" {
|
||||
buildObj := qualifiedIdentObject(info, buildCall.Fun)
|
||||
if !isGooseImport(buildObj.Pkg().Path()) || buildObj.Name() != "Build" {
|
||||
return nil
|
||||
}
|
||||
return useCall
|
||||
return buildCall
|
||||
}
|
||||
|
||||
func isGooseImport(path string) bool {
|
||||
|
||||
@@ -21,5 +21,5 @@ import (
|
||||
)
|
||||
|
||||
func injectFooBar() FooBar {
|
||||
panic(goose.Use(Set))
|
||||
panic(goose.Build(Set))
|
||||
}
|
||||
|
||||
2
internal/goose/testdata/Cleanup/foo/goose.go
vendored
2
internal/goose/testdata/Cleanup/foo/goose.go
vendored
@@ -21,5 +21,5 @@ import (
|
||||
)
|
||||
|
||||
func injectBar() (*Bar, func()) {
|
||||
panic(goose.Use(provideFoo, provideBar))
|
||||
panic(goose.Build(provideFoo, provideBar))
|
||||
}
|
||||
|
||||
@@ -35,5 +35,5 @@ func provideMessage() string {
|
||||
}
|
||||
|
||||
func injectedMessage() string {
|
||||
panic(goose.Use(provideMessage))
|
||||
panic(goose.Build(provideMessage))
|
||||
}
|
||||
|
||||
@@ -21,5 +21,5 @@ import (
|
||||
)
|
||||
|
||||
func injectedMessage() string {
|
||||
panic(goose.Use(myFakeSet))
|
||||
panic(goose.Build(myFakeSet))
|
||||
}
|
||||
|
||||
@@ -22,5 +22,5 @@ import (
|
||||
)
|
||||
|
||||
func injectedMessage() string {
|
||||
panic(goose.Use(bar.Value))
|
||||
panic(goose.Build(bar.Value))
|
||||
}
|
||||
|
||||
@@ -24,5 +24,5 @@ import (
|
||||
)
|
||||
|
||||
func injectedFile() *os.File {
|
||||
panic(goose.Use(bar.Value))
|
||||
panic(goose.Build(bar.Value))
|
||||
}
|
||||
|
||||
@@ -22,5 +22,5 @@ import (
|
||||
)
|
||||
|
||||
func injectFooer() foo.Fooer {
|
||||
panic(goose.Use(Set))
|
||||
panic(goose.Build(Set))
|
||||
}
|
||||
|
||||
@@ -21,5 +21,5 @@ import (
|
||||
)
|
||||
|
||||
func injectFooBar(foo Foo) FooBar {
|
||||
panic(goose.Use(Set))
|
||||
panic(goose.Build(Set))
|
||||
}
|
||||
|
||||
@@ -21,5 +21,5 @@ import (
|
||||
)
|
||||
|
||||
func injectBar(foo Foo) Bar {
|
||||
panic(goose.Use(Set))
|
||||
panic(goose.Build(Set))
|
||||
}
|
||||
|
||||
@@ -21,5 +21,5 @@ import (
|
||||
)
|
||||
|
||||
func injectFooer() Fooer {
|
||||
panic(goose.Use(Set))
|
||||
panic(goose.Build(Set))
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
)
|
||||
|
||||
func injectFooBar() FooBar {
|
||||
panic(goose.Use(
|
||||
panic(goose.Build(
|
||||
provideBar,
|
||||
provideFooBar,
|
||||
goose.Bind(Fooer(nil), (*Bar)(nil))))
|
||||
|
||||
@@ -23,5 +23,5 @@ import (
|
||||
)
|
||||
|
||||
func inject(context stdcontext.Context, err struct{}) (context, error) {
|
||||
panic(goose.Use(provide))
|
||||
panic(goose.Build(provide))
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ func Provide(context2 stdcontext.Context) (context, error) {
|
||||
}
|
||||
|
||||
func inject(context stdcontext.Context, err struct{}) (context, error) {
|
||||
panic(goose.Use(Provide))
|
||||
panic(goose.Build(Provide))
|
||||
}
|
||||
|
||||
func (context) Provide() {
|
||||
|
||||
@@ -21,5 +21,5 @@ import (
|
||||
)
|
||||
|
||||
func injectedMessage() string {
|
||||
panic(goose.Use(provideMessage))
|
||||
panic(goose.Build(provideMessage))
|
||||
}
|
||||
|
||||
@@ -21,5 +21,5 @@ import (
|
||||
)
|
||||
|
||||
func injectedMessage() string {
|
||||
panic(goose.Use(goose.Value("Hello, World!")))
|
||||
panic(goose.Build(goose.Value("Hello, World!")))
|
||||
}
|
||||
|
||||
@@ -21,5 +21,5 @@ import (
|
||||
)
|
||||
|
||||
func injectFooer() Fooer {
|
||||
panic(goose.Use(provideBar))
|
||||
panic(goose.Build(provideBar))
|
||||
}
|
||||
|
||||
@@ -26,5 +26,5 @@ import (
|
||||
// parameter names on the inject stub.
|
||||
|
||||
func inject(stdcontext.Context, struct{}) (context, error) {
|
||||
panic(goose.Use(provide))
|
||||
panic(goose.Build(provide))
|
||||
}
|
||||
|
||||
@@ -21,5 +21,5 @@ import (
|
||||
)
|
||||
|
||||
func injectBaz() (Baz, func(), error) {
|
||||
panic(goose.Use(provideFoo, provideBar, provideBaz))
|
||||
panic(goose.Build(provideFoo, provideBar, provideBaz))
|
||||
}
|
||||
|
||||
@@ -21,5 +21,5 @@ import (
|
||||
)
|
||||
|
||||
func injectFooBar() FooBar {
|
||||
panic(goose.Use(Set))
|
||||
panic(goose.Build(Set))
|
||||
}
|
||||
|
||||
@@ -21,5 +21,5 @@ import (
|
||||
)
|
||||
|
||||
func injectFoo() (Foo, error) {
|
||||
panic(goose.Use(Set))
|
||||
panic(goose.Build(Set))
|
||||
}
|
||||
|
||||
2
internal/goose/testdata/Struct/foo/goose.go
vendored
2
internal/goose/testdata/Struct/foo/goose.go
vendored
@@ -21,5 +21,5 @@ import (
|
||||
)
|
||||
|
||||
func injectFooBar() FooBar {
|
||||
panic(goose.Use(Set))
|
||||
panic(goose.Build(Set))
|
||||
}
|
||||
|
||||
@@ -21,5 +21,5 @@ import (
|
||||
)
|
||||
|
||||
func injectFooBar() *FooBar {
|
||||
panic(goose.Use(Set))
|
||||
panic(goose.Build(Set))
|
||||
}
|
||||
|
||||
@@ -21,5 +21,5 @@ import (
|
||||
)
|
||||
|
||||
func injectFooBar() FooBar {
|
||||
panic(goose.Use(Set))
|
||||
panic(goose.Build(Set))
|
||||
}
|
||||
|
||||
@@ -22,5 +22,5 @@ import (
|
||||
)
|
||||
|
||||
func injectedMessage() string {
|
||||
panic(goose.Use(bar.Value))
|
||||
panic(goose.Build(bar.Value))
|
||||
}
|
||||
|
||||
@@ -21,5 +21,5 @@ import (
|
||||
)
|
||||
|
||||
func injectFooBar() FooBar {
|
||||
panic(goose.Use(Set))
|
||||
panic(goose.Build(Set))
|
||||
}
|
||||
|
||||
@@ -21,5 +21,5 @@ import (
|
||||
)
|
||||
|
||||
func injectedMessage() Foo {
|
||||
panic(goose.Use(goose.Value(Foo("Hello, World!"))))
|
||||
panic(goose.Build(goose.Value(Foo("Hello, World!"))))
|
||||
}
|
||||
|
||||
@@ -21,5 +21,5 @@ import (
|
||||
)
|
||||
|
||||
func injectedMessage() string {
|
||||
panic(goose.Use(goose.Value(msg)))
|
||||
panic(goose.Build(goose.Value(msg)))
|
||||
}
|
||||
|
||||
2
internal/goose/testdata/Vendor/foo/goose.go
vendored
2
internal/goose/testdata/Vendor/foo/goose.go
vendored
@@ -22,5 +22,5 @@ import (
|
||||
)
|
||||
|
||||
func injectedMessage() string {
|
||||
panic(goose.Use(bar.ProvideMessage))
|
||||
panic(goose.Build(bar.ProvideMessage))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user