diff --git a/README.md b/README.md index d47ab72..3742c5e 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ calls providers in dependency order. With goose, you write the injector's signature, then goose generates the function's body. An injector is declared by writing a function declaration whose body is a call -to `panic()` with a call to `goose.Use` as its argument. Let's say that the +to `panic()` with a call to `goose.Build` as its argument. Let's say that the above providers were defined in a package called `example.com/foobarbaz`. The following would declare an injector to obtain a `Baz`: @@ -121,12 +121,12 @@ import ( ) func initializeApp(ctx context.Context) (foobarbaz.Baz, error) { - panic(goose.Use(foobarbaz.MegaSet)) + panic(goose.Build(foobarbaz.MegaSet)) } ``` Like providers, injectors can be parameterized on inputs (which then get sent to -providers) and can return errors. Arguments to `goose.Use` are the same as +providers) and can return errors. Arguments to `goose.Build` are the same as `goose.NewSet`: they form a provider set. This is the provider set that gets used during code generation for that injector. @@ -314,7 +314,7 @@ add a value expression to a provider set. type Foo int func injectFoo() Foo { - panic(goose.Use(goose.Value(Foo(42)))) + panic(goose.Build(goose.Value(Foo(42)))) } ``` diff --git a/goose.go b/goose.go index 0332f0b..c814442 100644 --- a/goose.go +++ b/goose.go @@ -25,16 +25,16 @@ func NewSet(...interface{}) ProviderSet { return ProviderSet{} } -// Use is placed in the body of an injector function to declare the +// Build is placed in the body of an injector function to declare the // providers to use. Its arguments are the same as NewSet. Its return // value is an error message that can be sent to panic. // // Example: // // func injector(ctx context.Context) (*sql.DB, error) { -// panic(Use(otherpkg.Foo, myProviderFunc, goose.Bind())) +// panic(Build(otherpkg.Foo, myProviderFunc, goose.Bind())) // } -func Use(...interface{}) string { +func Build(...interface{}) string { return "implementation not generated, run goose" } diff --git a/internal/goose/goose.go b/internal/goose/goose.go index 07984f3..69381b2 100644 --- a/internal/goose/goose.go +++ b/internal/goose/goose.go @@ -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) } diff --git a/internal/goose/parse.go b/internal/goose/parse.go index e829642..e6691e7 100644 --- a/internal/goose/parse.go +++ b/internal/goose/parse.go @@ -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 { diff --git a/internal/goose/testdata/Chain/foo/foo_goose.go b/internal/goose/testdata/Chain/foo/foo_goose.go index 8f9227a..35e40ba 100644 --- a/internal/goose/testdata/Chain/foo/foo_goose.go +++ b/internal/goose/testdata/Chain/foo/foo_goose.go @@ -21,5 +21,5 @@ import ( ) func injectFooBar() FooBar { - panic(goose.Use(Set)) + panic(goose.Build(Set)) } diff --git a/internal/goose/testdata/Cleanup/foo/goose.go b/internal/goose/testdata/Cleanup/foo/goose.go index f28d437..6b37bc1 100644 --- a/internal/goose/testdata/Cleanup/foo/goose.go +++ b/internal/goose/testdata/Cleanup/foo/goose.go @@ -21,5 +21,5 @@ import ( ) func injectBar() (*Bar, func()) { - panic(goose.Use(provideFoo, provideBar)) + panic(goose.Build(provideFoo, provideBar)) } diff --git a/internal/goose/testdata/CopyOtherDecls/foo/foo.go b/internal/goose/testdata/CopyOtherDecls/foo/foo.go index 2651c64..6293ec2 100644 --- a/internal/goose/testdata/CopyOtherDecls/foo/foo.go +++ b/internal/goose/testdata/CopyOtherDecls/foo/foo.go @@ -35,5 +35,5 @@ func provideMessage() string { } func injectedMessage() string { - panic(goose.Use(provideMessage)) + panic(goose.Build(provideMessage)) } diff --git a/internal/goose/testdata/EmptyVar/foo/goose.go b/internal/goose/testdata/EmptyVar/foo/goose.go index ee202fc..55b232e 100644 --- a/internal/goose/testdata/EmptyVar/foo/goose.go +++ b/internal/goose/testdata/EmptyVar/foo/goose.go @@ -21,5 +21,5 @@ import ( ) func injectedMessage() string { - panic(goose.Use(myFakeSet)) + panic(goose.Build(myFakeSet)) } diff --git a/internal/goose/testdata/ExportedValue/foo/goose.go b/internal/goose/testdata/ExportedValue/foo/goose.go index 0cdcb8f..a37e0ce 100644 --- a/internal/goose/testdata/ExportedValue/foo/goose.go +++ b/internal/goose/testdata/ExportedValue/foo/goose.go @@ -22,5 +22,5 @@ import ( ) func injectedMessage() string { - panic(goose.Use(bar.Value)) + panic(goose.Build(bar.Value)) } diff --git a/internal/goose/testdata/ExportedValueDifferentPackage/foo/goose.go b/internal/goose/testdata/ExportedValueDifferentPackage/foo/goose.go index af2916c..d8a4a2f 100644 --- a/internal/goose/testdata/ExportedValueDifferentPackage/foo/goose.go +++ b/internal/goose/testdata/ExportedValueDifferentPackage/foo/goose.go @@ -24,5 +24,5 @@ import ( ) func injectedFile() *os.File { - panic(goose.Use(bar.Value)) + panic(goose.Build(bar.Value)) } diff --git a/internal/goose/testdata/ImportedInterfaceBinding/bar/goose.go b/internal/goose/testdata/ImportedInterfaceBinding/bar/goose.go index 8783b33..06d5aaf 100644 --- a/internal/goose/testdata/ImportedInterfaceBinding/bar/goose.go +++ b/internal/goose/testdata/ImportedInterfaceBinding/bar/goose.go @@ -22,5 +22,5 @@ import ( ) func injectFooer() foo.Fooer { - panic(goose.Use(Set)) + panic(goose.Build(Set)) } diff --git a/internal/goose/testdata/InjectInput/foo/foo_goose.go b/internal/goose/testdata/InjectInput/foo/foo_goose.go index d114458..c08a9a3 100644 --- a/internal/goose/testdata/InjectInput/foo/foo_goose.go +++ b/internal/goose/testdata/InjectInput/foo/foo_goose.go @@ -21,5 +21,5 @@ import ( ) func injectFooBar(foo Foo) FooBar { - panic(goose.Use(Set)) + panic(goose.Build(Set)) } diff --git a/internal/goose/testdata/InjectInputConflict/foo/foo_goose.go b/internal/goose/testdata/InjectInputConflict/foo/foo_goose.go index b4ee0c7..91d9c3f 100644 --- a/internal/goose/testdata/InjectInputConflict/foo/foo_goose.go +++ b/internal/goose/testdata/InjectInputConflict/foo/foo_goose.go @@ -21,5 +21,5 @@ import ( ) func injectBar(foo Foo) Bar { - panic(goose.Use(Set)) + panic(goose.Build(Set)) } diff --git a/internal/goose/testdata/InterfaceBinding/foo/foo_goose.go b/internal/goose/testdata/InterfaceBinding/foo/foo_goose.go index 5f62ec8..3b3fbf6 100644 --- a/internal/goose/testdata/InterfaceBinding/foo/foo_goose.go +++ b/internal/goose/testdata/InterfaceBinding/foo/foo_goose.go @@ -21,5 +21,5 @@ import ( ) func injectFooer() Fooer { - panic(goose.Use(Set)) + panic(goose.Build(Set)) } diff --git a/internal/goose/testdata/InterfaceBindingReuse/foo/foo_goose.go b/internal/goose/testdata/InterfaceBindingReuse/foo/foo_goose.go index 1f5c0ce..85f08cc 100644 --- a/internal/goose/testdata/InterfaceBindingReuse/foo/foo_goose.go +++ b/internal/goose/testdata/InterfaceBindingReuse/foo/foo_goose.go @@ -21,7 +21,7 @@ import ( ) func injectFooBar() FooBar { - panic(goose.Use( + panic(goose.Build( provideBar, provideFooBar, goose.Bind(Fooer(nil), (*Bar)(nil)))) diff --git a/internal/goose/testdata/NamingWorstCase/foo/goose.go b/internal/goose/testdata/NamingWorstCase/foo/goose.go index e2e9f05..c4f22c5 100644 --- a/internal/goose/testdata/NamingWorstCase/foo/goose.go +++ b/internal/goose/testdata/NamingWorstCase/foo/goose.go @@ -23,5 +23,5 @@ import ( ) func inject(context stdcontext.Context, err struct{}) (context, error) { - panic(goose.Use(provide)) + panic(goose.Build(provide)) } diff --git a/internal/goose/testdata/NamingWorstCaseAllInOne/foo/foo.go b/internal/goose/testdata/NamingWorstCaseAllInOne/foo/foo.go index 4936874..2255582 100644 --- a/internal/goose/testdata/NamingWorstCaseAllInOne/foo/foo.go +++ b/internal/goose/testdata/NamingWorstCaseAllInOne/foo/foo.go @@ -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() { diff --git a/internal/goose/testdata/NiladicIdentity/foo/foo_goose.go b/internal/goose/testdata/NiladicIdentity/foo/foo_goose.go index d79b037..52fa33c 100644 --- a/internal/goose/testdata/NiladicIdentity/foo/foo_goose.go +++ b/internal/goose/testdata/NiladicIdentity/foo/foo_goose.go @@ -21,5 +21,5 @@ import ( ) func injectedMessage() string { - panic(goose.Use(provideMessage)) + panic(goose.Build(provideMessage)) } diff --git a/internal/goose/testdata/NiladicValue/foo/goose.go b/internal/goose/testdata/NiladicValue/foo/goose.go index 9fad6f7..da9be36 100644 --- a/internal/goose/testdata/NiladicValue/foo/goose.go +++ b/internal/goose/testdata/NiladicValue/foo/goose.go @@ -21,5 +21,5 @@ import ( ) func injectedMessage() string { - panic(goose.Use(goose.Value("Hello, World!"))) + panic(goose.Build(goose.Value("Hello, World!"))) } diff --git a/internal/goose/testdata/NoImplicitInterface/foo/foo_goose.go b/internal/goose/testdata/NoImplicitInterface/foo/foo_goose.go index d9db8d1..95386f5 100644 --- a/internal/goose/testdata/NoImplicitInterface/foo/foo_goose.go +++ b/internal/goose/testdata/NoImplicitInterface/foo/foo_goose.go @@ -21,5 +21,5 @@ import ( ) func injectFooer() Fooer { - panic(goose.Use(provideBar)) + panic(goose.Build(provideBar)) } diff --git a/internal/goose/testdata/NoInjectParamNames/foo/goose.go b/internal/goose/testdata/NoInjectParamNames/foo/goose.go index 7ca8ce4..503eb65 100644 --- a/internal/goose/testdata/NoInjectParamNames/foo/goose.go +++ b/internal/goose/testdata/NoInjectParamNames/foo/goose.go @@ -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)) } diff --git a/internal/goose/testdata/PartialCleanup/foo/goose.go b/internal/goose/testdata/PartialCleanup/foo/goose.go index 8fecb95..be69e63 100644 --- a/internal/goose/testdata/PartialCleanup/foo/goose.go +++ b/internal/goose/testdata/PartialCleanup/foo/goose.go @@ -21,5 +21,5 @@ import ( ) func injectBaz() (Baz, func(), error) { - panic(goose.Use(provideFoo, provideBar, provideBaz)) + panic(goose.Build(provideFoo, provideBar, provideBaz)) } diff --git a/internal/goose/testdata/PkgImport/foo/foo_goose.go b/internal/goose/testdata/PkgImport/foo/foo_goose.go index 8f9227a..35e40ba 100644 --- a/internal/goose/testdata/PkgImport/foo/foo_goose.go +++ b/internal/goose/testdata/PkgImport/foo/foo_goose.go @@ -21,5 +21,5 @@ import ( ) func injectFooBar() FooBar { - panic(goose.Use(Set)) + panic(goose.Build(Set)) } diff --git a/internal/goose/testdata/ReturnError/foo/foo_goose.go b/internal/goose/testdata/ReturnError/foo/foo_goose.go index caa84d7..0ebfb90 100644 --- a/internal/goose/testdata/ReturnError/foo/foo_goose.go +++ b/internal/goose/testdata/ReturnError/foo/foo_goose.go @@ -21,5 +21,5 @@ import ( ) func injectFoo() (Foo, error) { - panic(goose.Use(Set)) + panic(goose.Build(Set)) } diff --git a/internal/goose/testdata/Struct/foo/goose.go b/internal/goose/testdata/Struct/foo/goose.go index 8f9227a..35e40ba 100644 --- a/internal/goose/testdata/Struct/foo/goose.go +++ b/internal/goose/testdata/Struct/foo/goose.go @@ -21,5 +21,5 @@ import ( ) func injectFooBar() FooBar { - panic(goose.Use(Set)) + panic(goose.Build(Set)) } diff --git a/internal/goose/testdata/StructPointer/foo/goose.go b/internal/goose/testdata/StructPointer/foo/goose.go index 0b5c2b2..f64f20f 100644 --- a/internal/goose/testdata/StructPointer/foo/goose.go +++ b/internal/goose/testdata/StructPointer/foo/goose.go @@ -21,5 +21,5 @@ import ( ) func injectFooBar() *FooBar { - panic(goose.Use(Set)) + panic(goose.Build(Set)) } diff --git a/internal/goose/testdata/TwoDeps/foo/foo_goose.go b/internal/goose/testdata/TwoDeps/foo/foo_goose.go index 8f9227a..35e40ba 100644 --- a/internal/goose/testdata/TwoDeps/foo/foo_goose.go +++ b/internal/goose/testdata/TwoDeps/foo/foo_goose.go @@ -21,5 +21,5 @@ import ( ) func injectFooBar() FooBar { - panic(goose.Use(Set)) + panic(goose.Build(Set)) } diff --git a/internal/goose/testdata/UnexportedValue/foo/goose.go b/internal/goose/testdata/UnexportedValue/foo/goose.go index 0cdcb8f..a37e0ce 100644 --- a/internal/goose/testdata/UnexportedValue/foo/goose.go +++ b/internal/goose/testdata/UnexportedValue/foo/goose.go @@ -22,5 +22,5 @@ import ( ) func injectedMessage() string { - panic(goose.Use(bar.Value)) + panic(goose.Build(bar.Value)) } diff --git a/internal/goose/testdata/ValueChain/foo/goose.go b/internal/goose/testdata/ValueChain/foo/goose.go index 8f9227a..35e40ba 100644 --- a/internal/goose/testdata/ValueChain/foo/goose.go +++ b/internal/goose/testdata/ValueChain/foo/goose.go @@ -21,5 +21,5 @@ import ( ) func injectFooBar() FooBar { - panic(goose.Use(Set)) + panic(goose.Build(Set)) } diff --git a/internal/goose/testdata/ValueConversion/foo/goose.go b/internal/goose/testdata/ValueConversion/foo/goose.go index 1ae73ab..098740d 100644 --- a/internal/goose/testdata/ValueConversion/foo/goose.go +++ b/internal/goose/testdata/ValueConversion/foo/goose.go @@ -21,5 +21,5 @@ import ( ) func injectedMessage() Foo { - panic(goose.Use(goose.Value(Foo("Hello, World!")))) + panic(goose.Build(goose.Value(Foo("Hello, World!")))) } diff --git a/internal/goose/testdata/VarValue/foo/goose.go b/internal/goose/testdata/VarValue/foo/goose.go index 4c5ec31..b4286aa 100644 --- a/internal/goose/testdata/VarValue/foo/goose.go +++ b/internal/goose/testdata/VarValue/foo/goose.go @@ -21,5 +21,5 @@ import ( ) func injectedMessage() string { - panic(goose.Use(goose.Value(msg))) + panic(goose.Build(goose.Value(msg))) } diff --git a/internal/goose/testdata/Vendor/foo/goose.go b/internal/goose/testdata/Vendor/foo/goose.go index 8ddfba7..4540ef8 100644 --- a/internal/goose/testdata/Vendor/foo/goose.go +++ b/internal/goose/testdata/Vendor/foo/goose.go @@ -22,5 +22,5 @@ import ( ) func injectedMessage() string { - panic(goose.Use(bar.ProvideMessage)) + panic(goose.Build(bar.ProvideMessage)) }