From 6345348d86a0db45130ea7b42331f49a294a76b4 Mon Sep 17 00:00:00 2001 From: Ross Light Date: Thu, 31 May 2018 15:34:15 -0700 Subject: [PATCH] wire: rename from Goose (google/go-cloud#59) Rename Goose to wire, making it more obvious what the package does, and look more like the stdlib. Fixes google/go-cloud#8 --- README.md | 76 +++++++++---------- cmd/{goose => gowire}/main.go | 42 +++++----- .../goose/testdata/NiladicValue/foo/goose.go | 25 ------ .../goose/testdata/ValueChain/foo/goose.go | 25 ------ internal/goose/testdata/VarValue/foo/goose.go | 25 ------ internal/{goose => wire}/analyze.go | 2 +- internal/{goose => wire}/copyast.go | 2 +- internal/{goose => wire}/parse.go | 32 ++++---- .../{goose => wire}/testdata/Chain/foo/foo.go | 4 +- .../testdata/Chain/foo/wire.go} | 6 +- .../{goose => wire}/testdata/Chain/out.txt | 0 internal/{goose => wire}/testdata/Chain/pkg | 0 .../testdata/Cleanup/foo/foo.go | 0 .../testdata/Cleanup/foo/wire.go} | 6 +- .../{goose => wire}/testdata/Cleanup/out.txt | 0 internal/{goose => wire}/testdata/Cleanup/pkg | 0 .../testdata/CopyOtherDecls/foo/foo.go | 8 +- .../testdata/CopyOtherDecls/out.txt | 0 .../testdata/CopyOtherDecls/pkg | 0 .../testdata/EmptyVar/foo/foo.go | 0 .../testdata/EmptyVar/foo/wire.go} | 6 +- .../{goose => wire}/testdata/EmptyVar/out.txt | 0 .../{goose => wire}/testdata/EmptyVar/pkg | 0 .../testdata/ExportedValue/bar/bar.go | 4 +- .../testdata/ExportedValue/foo/foo.go | 0 .../testdata/ExportedValue/foo/wire.go} | 6 +- .../testdata/ExportedValue/out.txt | 0 .../testdata/ExportedValue/pkg | 0 .../ExportedValueDifferentPackage/bar/bar.go | 4 +- .../ExportedValueDifferentPackage/foo/foo.go | 0 .../foo/wire.go} | 6 +- .../ExportedValueDifferentPackage/out.txt | 0 .../ExportedValueDifferentPackage/pkg | 0 .../ImportedInterfaceBinding/bar/bar.go | 6 +- .../ImportedInterfaceBinding/bar/wire.go} | 6 +- .../ImportedInterfaceBinding/foo/foo.go | 0 .../testdata/ImportedInterfaceBinding/out.txt | 0 .../testdata/ImportedInterfaceBinding/pkg | 0 .../testdata/InjectInput/foo/foo.go | 4 +- .../testdata/InjectInput/foo/wire.go} | 6 +- .../testdata/InjectInput/out.txt | 0 .../{goose => wire}/testdata/InjectInput/pkg | 0 .../testdata/InjectInputConflict/foo/foo.go | 4 +- .../testdata/InjectInputConflict/foo/wire.go} | 6 +- .../testdata/InjectInputConflict/out.txt | 0 .../testdata/InjectInputConflict/pkg | 0 .../testdata/InterfaceBinding/foo/foo.go | 6 +- .../testdata/InterfaceBinding/foo/wire.go} | 6 +- .../testdata/InterfaceBinding/out.txt | 0 .../testdata/InterfaceBinding/pkg | 0 .../testdata/InterfaceBindingReuse/foo/foo.go | 0 .../InterfaceBindingReuse/foo/wire.go} | 8 +- .../testdata/InterfaceBindingReuse/out.txt | 0 .../testdata/InterfaceBindingReuse/pkg | 0 .../testdata/NamingWorstCase/foo/foo.go | 0 .../testdata/NamingWorstCase/foo/wire.go} | 6 +- .../testdata/NamingWorstCase/out.txt | 0 .../testdata/NamingWorstCase/pkg | 0 .../NamingWorstCaseAllInOne/foo/foo.go | 6 +- .../testdata/NamingWorstCaseAllInOne/out.txt | 0 .../testdata/NamingWorstCaseAllInOne/pkg | 0 .../testdata/NiladicIdentity/foo/foo.go | 0 .../testdata/NiladicIdentity/foo/wire.go} | 6 +- .../testdata/NiladicIdentity/out.txt | 0 .../testdata/NiladicIdentity/pkg | 0 .../testdata/NiladicValue/foo/foo.go | 0 .../wire/testdata/NiladicValue/foo/wire.go | 25 ++++++ .../testdata/NiladicValue/out.txt | 0 .../{goose => wire}/testdata/NiladicValue/pkg | 0 .../testdata/NoImplicitInterface/foo/foo.go | 0 .../testdata/NoImplicitInterface/foo/wire.go} | 6 +- .../testdata/NoImplicitInterface/out.txt | 0 .../testdata/NoImplicitInterface/pkg | 0 .../testdata/NoInjectParamNames/foo/foo.go | 0 .../testdata/NoInjectParamNames/foo/wire.go} | 6 +- .../testdata/NoInjectParamNames/out.txt | 0 .../testdata/NoInjectParamNames/pkg | 0 .../testdata/NoopBuild/foo/foo.go | 0 .../testdata/NoopBuild/out.txt | 0 .../{goose => wire}/testdata/NoopBuild/pkg | 0 .../testdata/PartialCleanup/foo/foo.go | 0 .../testdata/PartialCleanup/foo/wire.go} | 6 +- .../testdata/PartialCleanup/out.txt | 0 .../testdata/PartialCleanup/pkg | 0 .../testdata/PkgImport/bar/bar.go | 0 .../testdata/PkgImport/foo/foo.go | 4 +- .../testdata/PkgImport/foo/wire.go} | 6 +- .../testdata/PkgImport/out.txt | 0 .../{goose => wire}/testdata/PkgImport/pkg | 0 .../testdata/ReturnError/foo/foo.go | 4 +- .../testdata/ReturnError/foo/wire.go} | 6 +- .../testdata/ReturnError/out.txt | 0 .../{goose => wire}/testdata/ReturnError/pkg | 0 .../testdata/Struct/foo/foo.go | 4 +- .../testdata/Struct/foo/wire.go} | 6 +- .../{goose => wire}/testdata/Struct/out.txt | 0 internal/{goose => wire}/testdata/Struct/pkg | 0 .../testdata/StructPointer/foo/foo.go | 4 +- .../testdata/StructPointer/foo/wire.go} | 6 +- .../testdata/StructPointer/out.txt | 0 .../testdata/StructPointer/pkg | 0 .../testdata/TwoDeps/foo/foo.go | 4 +- .../testdata/TwoDeps/foo/wire.go} | 6 +- .../{goose => wire}/testdata/TwoDeps/out.txt | 0 internal/{goose => wire}/testdata/TwoDeps/pkg | 0 .../testdata/UnexportedValue/bar/bar.go | 4 +- .../testdata/UnexportedValue/foo/foo.go | 0 .../testdata/UnexportedValue/foo/wire.go} | 6 +- .../testdata/UnexportedValue/out.txt | 0 .../testdata/UnexportedValue/pkg | 0 .../testdata/ValueChain/foo/foo.go | 6 +- internal/wire/testdata/ValueChain/foo/wire.go | 25 ++++++ .../testdata/ValueChain/out.txt | 0 .../{goose => wire}/testdata/ValueChain/pkg | 0 .../testdata/ValueConversion/foo/foo.go | 0 .../testdata/ValueConversion/foo/wire.go} | 6 +- .../testdata/ValueConversion/out.txt | 0 .../testdata/ValueConversion/pkg | 0 .../testdata/VarValue/foo/foo.go | 0 internal/wire/testdata/VarValue/foo/wire.go | 25 ++++++ .../{goose => wire}/testdata/VarValue/out.txt | 0 .../{goose => wire}/testdata/VarValue/pkg | 0 .../testdata/Vendor/bar/dummy.go | 0 .../testdata/Vendor/foo/foo.go | 0 .../testdata/Vendor/foo/vendor/bar/bar.go | 0 .../testdata/Vendor/foo/wire.go} | 6 +- .../{goose => wire}/testdata/Vendor/out.txt | 0 internal/{goose => wire}/testdata/Vendor/pkg | 0 internal/{goose/goose.go => wire/wire.go} | 10 +-- .../goose_test.go => wire/wire_test.go} | 36 ++++----- goose.go => wire.go | 12 +-- 131 files changed, 285 insertions(+), 293 deletions(-) rename cmd/{goose => gowire}/main.go (89%) delete mode 100644 internal/goose/testdata/NiladicValue/foo/goose.go delete mode 100644 internal/goose/testdata/ValueChain/foo/goose.go delete mode 100644 internal/goose/testdata/VarValue/foo/goose.go rename internal/{goose => wire}/analyze.go (99%) rename internal/{goose => wire}/copyast.go (99%) rename internal/{goose => wire}/parse.go (94%) rename internal/{goose => wire}/testdata/Chain/foo/foo.go (93%) rename internal/{goose/testdata/Chain/foo/foo_goose.go => wire/testdata/Chain/foo/wire.go} (88%) rename internal/{goose => wire}/testdata/Chain/out.txt (100%) rename internal/{goose => wire}/testdata/Chain/pkg (100%) rename internal/{goose => wire}/testdata/Cleanup/foo/foo.go (100%) rename internal/{goose/testdata/Cleanup/foo/goose.go => wire/testdata/Cleanup/foo/wire.go} (86%) rename internal/{goose => wire}/testdata/Cleanup/out.txt (100%) rename internal/{goose => wire}/testdata/Cleanup/pkg (100%) rename internal/{goose => wire}/testdata/CopyOtherDecls/foo/foo.go (84%) rename internal/{goose => wire}/testdata/CopyOtherDecls/out.txt (100%) rename internal/{goose => wire}/testdata/CopyOtherDecls/pkg (100%) rename internal/{goose => wire}/testdata/EmptyVar/foo/foo.go (100%) rename internal/{goose/testdata/EmptyVar/foo/goose.go => wire/testdata/EmptyVar/foo/wire.go} (88%) rename internal/{goose => wire}/testdata/EmptyVar/out.txt (100%) rename internal/{goose => wire}/testdata/EmptyVar/pkg (100%) rename internal/{goose => wire}/testdata/ExportedValue/bar/bar.go (89%) rename internal/{goose => wire}/testdata/ExportedValue/foo/foo.go (100%) rename internal/{goose/testdata/UnexportedValue/foo/goose.go => wire/testdata/ExportedValue/foo/wire.go} (88%) rename internal/{goose => wire}/testdata/ExportedValue/out.txt (100%) rename internal/{goose => wire}/testdata/ExportedValue/pkg (100%) rename internal/{goose => wire}/testdata/ExportedValueDifferentPackage/bar/bar.go (89%) rename internal/{goose => wire}/testdata/ExportedValueDifferentPackage/foo/foo.go (100%) rename internal/{goose/testdata/ExportedValueDifferentPackage/foo/goose.go => wire/testdata/ExportedValueDifferentPackage/foo/wire.go} (88%) rename internal/{goose => wire}/testdata/ExportedValueDifferentPackage/out.txt (100%) rename internal/{goose => wire}/testdata/ExportedValueDifferentPackage/pkg (100%) rename internal/{goose => wire}/testdata/ImportedInterfaceBinding/bar/bar.go (88%) rename internal/{goose/testdata/ImportedInterfaceBinding/bar/goose.go => wire/testdata/ImportedInterfaceBinding/bar/wire.go} (88%) rename internal/{goose => wire}/testdata/ImportedInterfaceBinding/foo/foo.go (100%) rename internal/{goose => wire}/testdata/ImportedInterfaceBinding/out.txt (100%) rename internal/{goose => wire}/testdata/ImportedInterfaceBinding/pkg (100%) rename internal/{goose => wire}/testdata/InjectInput/foo/foo.go (93%) rename internal/{goose/testdata/InjectInput/foo/foo_goose.go => wire/testdata/InjectInput/foo/wire.go} (88%) rename internal/{goose => wire}/testdata/InjectInput/out.txt (100%) rename internal/{goose => wire}/testdata/InjectInput/pkg (100%) rename internal/{goose => wire}/testdata/InjectInputConflict/foo/foo.go (94%) rename internal/{goose/testdata/InjectInputConflict/foo/foo_goose.go => wire/testdata/InjectInputConflict/foo/wire.go} (88%) rename internal/{goose => wire}/testdata/InjectInputConflict/out.txt (100%) rename internal/{goose => wire}/testdata/InjectInputConflict/pkg (100%) rename internal/{goose => wire}/testdata/InterfaceBinding/foo/foo.go (89%) rename internal/{goose/testdata/InterfaceBinding/foo/foo_goose.go => wire/testdata/InterfaceBinding/foo/wire.go} (88%) rename internal/{goose => wire}/testdata/InterfaceBinding/out.txt (100%) rename internal/{goose => wire}/testdata/InterfaceBinding/pkg (100%) rename internal/{goose => wire}/testdata/InterfaceBindingReuse/foo/foo.go (100%) rename internal/{goose/testdata/InterfaceBindingReuse/foo/foo_goose.go => wire/testdata/InterfaceBindingReuse/foo/wire.go} (84%) rename internal/{goose => wire}/testdata/InterfaceBindingReuse/out.txt (100%) rename internal/{goose => wire}/testdata/InterfaceBindingReuse/pkg (100%) rename internal/{goose => wire}/testdata/NamingWorstCase/foo/foo.go (100%) rename internal/{goose/testdata/NamingWorstCase/foo/goose.go => wire/testdata/NamingWorstCase/foo/wire.go} (89%) rename internal/{goose => wire}/testdata/NamingWorstCase/out.txt (100%) rename internal/{goose => wire}/testdata/NamingWorstCase/pkg (100%) rename internal/{goose => wire}/testdata/NamingWorstCaseAllInOne/foo/foo.go (94%) rename internal/{goose => wire}/testdata/NamingWorstCaseAllInOne/out.txt (100%) rename internal/{goose => wire}/testdata/NamingWorstCaseAllInOne/pkg (100%) rename internal/{goose => wire}/testdata/NiladicIdentity/foo/foo.go (100%) rename internal/{goose/testdata/NiladicIdentity/foo/foo_goose.go => wire/testdata/NiladicIdentity/foo/wire.go} (87%) rename internal/{goose => wire}/testdata/NiladicIdentity/out.txt (100%) rename internal/{goose => wire}/testdata/NiladicIdentity/pkg (100%) rename internal/{goose => wire}/testdata/NiladicValue/foo/foo.go (100%) create mode 100644 internal/wire/testdata/NiladicValue/foo/wire.go rename internal/{goose => wire}/testdata/NiladicValue/out.txt (100%) rename internal/{goose => wire}/testdata/NiladicValue/pkg (100%) rename internal/{goose => wire}/testdata/NoImplicitInterface/foo/foo.go (100%) rename internal/{goose/testdata/NoImplicitInterface/foo/foo_goose.go => wire/testdata/NoImplicitInterface/foo/wire.go} (87%) rename internal/{goose => wire}/testdata/NoImplicitInterface/out.txt (100%) rename internal/{goose => wire}/testdata/NoImplicitInterface/pkg (100%) rename internal/{goose => wire}/testdata/NoInjectParamNames/foo/foo.go (100%) rename internal/{goose/testdata/NoInjectParamNames/foo/goose.go => wire/testdata/NoInjectParamNames/foo/wire.go} (90%) rename internal/{goose => wire}/testdata/NoInjectParamNames/out.txt (100%) rename internal/{goose => wire}/testdata/NoInjectParamNames/pkg (100%) rename internal/{goose => wire}/testdata/NoopBuild/foo/foo.go (100%) rename internal/{goose => wire}/testdata/NoopBuild/out.txt (100%) rename internal/{goose => wire}/testdata/NoopBuild/pkg (100%) rename internal/{goose => wire}/testdata/PartialCleanup/foo/foo.go (100%) rename internal/{goose/testdata/PartialCleanup/foo/goose.go => wire/testdata/PartialCleanup/foo/wire.go} (85%) rename internal/{goose => wire}/testdata/PartialCleanup/out.txt (100%) rename internal/{goose => wire}/testdata/PartialCleanup/pkg (100%) rename internal/{goose => wire}/testdata/PkgImport/bar/bar.go (100%) rename internal/{goose => wire}/testdata/PkgImport/foo/foo.go (93%) rename internal/{goose/testdata/PkgImport/foo/foo_goose.go => wire/testdata/PkgImport/foo/wire.go} (88%) rename internal/{goose => wire}/testdata/PkgImport/out.txt (100%) rename internal/{goose => wire}/testdata/PkgImport/pkg (100%) rename internal/{goose => wire}/testdata/ReturnError/foo/foo.go (93%) rename internal/{goose/testdata/ReturnError/foo/foo_goose.go => wire/testdata/ReturnError/foo/wire.go} (88%) rename internal/{goose => wire}/testdata/ReturnError/out.txt (100%) rename internal/{goose => wire}/testdata/ReturnError/pkg (100%) rename internal/{goose => wire}/testdata/Struct/foo/foo.go (93%) rename internal/{goose/testdata/Struct/foo/goose.go => wire/testdata/Struct/foo/wire.go} (88%) rename internal/{goose => wire}/testdata/Struct/out.txt (100%) rename internal/{goose => wire}/testdata/Struct/pkg (100%) rename internal/{goose => wire}/testdata/StructPointer/foo/foo.go (93%) rename internal/{goose/testdata/StructPointer/foo/goose.go => wire/testdata/StructPointer/foo/wire.go} (88%) rename internal/{goose => wire}/testdata/StructPointer/out.txt (100%) rename internal/{goose => wire}/testdata/StructPointer/pkg (100%) rename internal/{goose => wire}/testdata/TwoDeps/foo/foo.go (93%) rename internal/{goose/testdata/TwoDeps/foo/foo_goose.go => wire/testdata/TwoDeps/foo/wire.go} (88%) rename internal/{goose => wire}/testdata/TwoDeps/out.txt (100%) rename internal/{goose => wire}/testdata/TwoDeps/pkg (100%) rename internal/{goose => wire}/testdata/UnexportedValue/bar/bar.go (89%) rename internal/{goose => wire}/testdata/UnexportedValue/foo/foo.go (100%) rename internal/{goose/testdata/ExportedValue/foo/goose.go => wire/testdata/UnexportedValue/foo/wire.go} (88%) rename internal/{goose => wire}/testdata/UnexportedValue/out.txt (100%) rename internal/{goose => wire}/testdata/UnexportedValue/pkg (100%) rename internal/{goose => wire}/testdata/ValueChain/foo/foo.go (90%) create mode 100644 internal/wire/testdata/ValueChain/foo/wire.go rename internal/{goose => wire}/testdata/ValueChain/out.txt (100%) rename internal/{goose => wire}/testdata/ValueChain/pkg (100%) rename internal/{goose => wire}/testdata/ValueConversion/foo/foo.go (100%) rename internal/{goose/testdata/ValueConversion/foo/goose.go => wire/testdata/ValueConversion/foo/wire.go} (85%) rename internal/{goose => wire}/testdata/ValueConversion/out.txt (100%) rename internal/{goose => wire}/testdata/ValueConversion/pkg (100%) rename internal/{goose => wire}/testdata/VarValue/foo/foo.go (100%) create mode 100644 internal/wire/testdata/VarValue/foo/wire.go rename internal/{goose => wire}/testdata/VarValue/out.txt (100%) rename internal/{goose => wire}/testdata/VarValue/pkg (100%) rename internal/{goose => wire}/testdata/Vendor/bar/dummy.go (100%) rename internal/{goose => wire}/testdata/Vendor/foo/foo.go (100%) rename internal/{goose => wire}/testdata/Vendor/foo/vendor/bar/bar.go (100%) rename internal/{goose/testdata/Vendor/foo/goose.go => wire/testdata/Vendor/foo/wire.go} (87%) rename internal/{goose => wire}/testdata/Vendor/out.txt (100%) rename internal/{goose => wire}/testdata/Vendor/pkg (100%) rename internal/{goose/goose.go => wire/wire.go} (98%) rename internal/{goose/goose_test.go => wire/wire_test.go} (93%) rename goose.go => wire.go (85%) diff --git a/README.md b/README.md index cecc85b..81860bf 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# goose: Compile-Time Dependency Injection for Go +# Wire: Compile-Time Dependency Injection for Go -goose is a compile-time [dependency injection][] framework for Go, inspired by +Wire is a static [dependency injection][] framework for Go, inspired by [Dagger][]. It works by using Go code to specify dependencies, then generating code to create those structures, mimicking the code that a user might have hand-written. @@ -12,7 +12,7 @@ might have hand-written. ### Defining Providers -The primary mechanism in goose is the **provider**: a function that can +The primary mechanism in Wire is the **provider**: a function that can produce a value. These functions are ordinary Go code. ```go @@ -65,19 +65,19 @@ func ProvideBaz(ctx context.Context, bar Bar) (Baz, error) { ``` Providers can be grouped in **provider sets**. To add these providers to a new -set called `SuperSet`, use the `goose.NewSet` function: +set called `SuperSet`, use the `wire.NewSet` function: ```go package foobarbaz import ( // ... - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) // ... -var SuperSet = goose.NewSet(ProvideFoo, ProvideBar, ProvideBaz) +var SuperSet = wire.NewSet(ProvideFoo, ProvideBar, ProvideBaz) ``` You can also add other provider sets into a provider set. @@ -92,22 +92,22 @@ import ( // ... -var MegaSet = goose.NewSet(SuperSet, pkg.OtherSet) +var MegaSet = wire.NewSet(SuperSet, pkg.OtherSet) ``` ### Injectors An application wires up these providers with an **injector**: a function that -calls providers in dependency order. With goose, you write the injector's -signature, then goose generates the function's body. +calls providers in dependency order. With Wire, you write the injector's +signature, then Wire 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.Build` as its argument. Let's say that the +to `panic()` with a call to `wire.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`: ```go -// +build gooseinject +// +build wireinject // ^ build tag makes sure the stub is not built in the final build @@ -116,30 +116,30 @@ package main import ( "context" - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" "example.com/foobarbaz" ) func initializeApp(ctx context.Context) (foobarbaz.Baz, error) { - panic(goose.Build(foobarbaz.MegaSet)) + panic(wire.Build(foobarbaz.MegaSet)) } ``` Like providers, injectors can be parameterized on inputs (which then get sent to -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 +providers) and can return errors. Arguments to `wire.Build` are the same as +`wire.NewSet`: they form a provider set. This is the provider set that gets used during code generation for that injector. Any non-injector declarations found in a file with injectors will be copied into the generated file. -You can generate the injector by invoking goose in the package directory: +You can generate the injector by invoking `gowire` in the package directory: ``` -goose +gowire ``` -Or you can add the line `//go:generate goose` to another file in your package to +Or you can add the line `//go:generate gowire` to another file in your package to use [`go generate`]: ``` @@ -149,13 +149,13 @@ go generate (Adding the line to the injection declaration file will be silently ignored by `go generate`.) -goose will produce an implementation of the injector in a file called -`goose_gen.go` that looks something like this: +Wire will produce an implementation of the injector in a file called +`wire_gen.go` that looks something like this: ```go -// Code generated by goose. DO NOT EDIT. +// Code generated by gowire. DO NOT EDIT. -//+build !gooseinject +//+build !wireinject package main @@ -175,15 +175,15 @@ func initializeApp(ctx context.Context) (foobarbaz.Baz, error) { ``` As you can see, the output is very close to what a developer would write -themselves. Further, there is little dependency on goose at runtime: all of the -written code is just normal Go code, and can be used without goose. +themselves. Further, there is little dependency on Wire at runtime: all of the +written code is just normal Go code, and can be used without Wire. [`go generate`]: https://blog.golang.org/generate ## Best Practices -goose is still not mature yet, but guidance that applies to Dagger generally -applies to goose as well. In particular, when thinking about how to group +Wire is still not mature yet, but guidance that applies to Dagger generally +applies to Wire as well. In particular, when thinking about how to group providers into sets, follow the same [guidance](https://google.github.io/dagger/testing.html#organize-modules-for-testability) as Dagger (provider sets are called modules in Dagger/Guice): @@ -209,7 +209,7 @@ as Dagger (provider sets are called modules in Dagger/Guice): > - The [provider sets] should each include the no-reasonable-alternative > [provider sets] that require the [...] bindings each provides. -One goose-specific practice though: create one-off types where in Java you +One Wire-specific practice though: create one-off types where in Java you would use a binding annotation. For example, if you need to pass a string through the dependency graph, you would create a wrapping type: @@ -222,7 +222,7 @@ type MySQLConnectionString string ### Binding Interfaces Frequently, dependency injection is used to bind concrete implementations for an -interface. goose matches inputs to outputs via [type identity][], so the +interface. Wire matches inputs to outputs via [type identity][], so the inclination might be to create a provider that returns an interface type. However, this would not be idiomatic, since the Go best practice is to [return concrete types][]. Instead, you can declare an interface binding in a @@ -245,12 +245,12 @@ func ProvideBar() *Bar { return b } -var BarFooer = goose.NewSet( +var BarFooer = wire.NewSet( ProvideBar, - goose.Bind(new(Fooer), new(Bar))) + wire.Bind(new(Fooer), new(Bar))) ``` -The first argument to `goose.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 interface type and the second argument is a zero value of the concrete type. An interface binding does not necessarily need to have a provider in the same set that provides the concrete type. @@ -282,7 +282,7 @@ type FooBar struct { Bar Bar } -var Set = goose.NewSet( +var Set = wire.NewSet( ProvideFoo, ProvideBar, FooBar{}) @@ -314,7 +314,7 @@ add a value expression to a provider set. type Foo int func injectFoo() Foo { - panic(goose.Build(goose.Value(Foo(42)))) + panic(wire.Build(wire.Value(Foo(42)))) } ``` @@ -328,7 +328,7 @@ func injectFoo() Foo { ``` It's important to note that the expression will be copied, so references to -variables will be evaluated during the call to the injector. goose will emit +variables will be evaluated during the call to the injector. `gowire` will emit an error if the expression calls any functions. ### Cleanup functions @@ -355,11 +355,3 @@ func provideFile(log Logger, path Path) (*os.File, func(), error) { A cleanup function is guaranteed to be called before the cleanup function of any of the provider's inputs and must have the signature `func()`. - -## Future Work - -- Support for map bindings. -- Support for multiple provider outputs. -- Tighter validation for a provider set (cycles in unused providers goes - unreported currently) -- Visualization for provider sets diff --git a/cmd/goose/main.go b/cmd/gowire/main.go similarity index 89% rename from cmd/goose/main.go rename to cmd/gowire/main.go index 479e621..b9c9ad3 100644 --- a/cmd/goose/main.go +++ b/cmd/gowire/main.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// goose is a compile-time dependency injection tool. +// gowire is a compile-time dependency injection tool. // // See README.md for an overview. package main @@ -30,7 +30,7 @@ import ( "strconv" "strings" - "github.com/google/go-cloud/goose/internal/goose" + "github.com/google/go-cloud/wire/internal/wire" "golang.org/x/tools/go/types/typeutil" ) @@ -48,17 +48,17 @@ func main() { case len(os.Args) == 3 && os.Args[1] == "gen": err = generate(os.Args[2]) default: - fmt.Fprintln(os.Stderr, "goose: usage: goose [gen] [PKG] | goose show [...]") + fmt.Fprintln(os.Stderr, "gowire: usage: gowire [gen] [PKG] | gowire show [...]") os.Exit(64) } if err != nil { - fmt.Fprintln(os.Stderr, "goose:", err) + fmt.Fprintln(os.Stderr, "gowire:", err) os.Exit(1) } } // generate runs the gen subcommand. Given a package, gen will create -// the goose_gen.go file. +// the wire_gen.go file. func generate(pkg string) error { wd, err := os.Getwd() if err != nil { @@ -68,16 +68,16 @@ func generate(pkg string) error { if err != nil { return err } - out, err := goose.Generate(&build.Default, wd, pkg) + out, err := wire.Generate(&build.Default, wd, pkg) if err != nil { return err } if len(out) == 0 { - // No Goose directives, don't write anything. - fmt.Fprintln(os.Stderr, "goose: no injector found for", pkg) + // No Wire directives, don't write anything. + fmt.Fprintln(os.Stderr, "gowire: no injector found for", pkg) return nil } - p := filepath.Join(pkgInfo.Dir, "goose_gen.go") + p := filepath.Join(pkgInfo.Dir, "wire_gen.go") if err := ioutil.WriteFile(p, out, 0666); err != nil { return err } @@ -94,11 +94,11 @@ func show(pkgs ...string) error { if err != nil { return err } - info, err := goose.Load(&build.Default, wd, pkgs) + info, err := wire.Load(&build.Default, wd, pkgs) if err != nil { return err } - keys := make([]goose.ProviderSetID, 0, len(info.Sets)) + keys := make([]wire.ProviderSetID, 0, len(info.Sets)) for k := range info.Sets { keys = append(keys, k) } @@ -130,11 +130,11 @@ func show(pkgs ...string) error { out := make(map[string]token.Pos, outGroups[i].outputs.Len()) outGroups[i].outputs.Iterate(func(t types.Type, v interface{}) { switch v := v.(type) { - case *goose.Provider: + case *wire.Provider: out[types.TypeString(t, nil)] = v.Pos - case *goose.Value: + case *wire.Value: out[types.TypeString(t, nil)] = v.Pos - case *goose.IfaceBinding: + case *wire.IfaceBinding: out[types.TypeString(t, nil)] = v.Pos default: panic("unreachable") @@ -152,19 +152,19 @@ func show(pkgs ...string) error { type outGroup struct { name string inputs *typeutil.Map // values are not important - outputs *typeutil.Map // values are *goose.Provider, *goose.Value, or *goose.IfaceBinding + outputs *typeutil.Map // values are *wire.Provider, *wire.Value, or *wire.IfaceBinding } // gather flattens a provider set into outputs grouped by the inputs // required to create them. As it flattens the provider set, it records // the visited named provider sets as imports. -func gather(info *goose.Info, key goose.ProviderSetID) (_ []outGroup, imports map[string]struct{}) { +func gather(info *wire.Info, key wire.ProviderSetID) (_ []outGroup, imports map[string]struct{}) { hash := typeutil.MakeHasher() // Map types to providers and bindings. pm := new(typeutil.Map) pm.SetHasher(hash) - next := []*goose.ProviderSet{info.Sets[key]} - visited := make(map[*goose.ProviderSet]struct{}) + next := []*wire.ProviderSet{info.Sets[key]} + visited := make(map[*wire.ProviderSet]struct{}) imports = make(map[string]struct{}) for len(next) > 0 { curr := next[len(next)-1] @@ -214,7 +214,7 @@ func gather(info *goose.Info, key goose.ProviderSetID) (_ []outGroup, imports ma case nil: // This is an input. inputVisited.Set(curr, -1) - case *goose.Provider: + case *wire.Provider: // Try to see if any args haven't been visited. allPresent := true for _, arg := range p.Args { @@ -258,7 +258,7 @@ func gather(info *goose.Info, key goose.ProviderSetID) (_ []outGroup, imports ma inputs: in, outputs: out, }) - case *goose.Value: + case *wire.Value: for i := range groups { if groups[i].inputs.Len() == 0 { groups[i].outputs.Set(p.Out, p) @@ -276,7 +276,7 @@ func gather(info *goose.Info, key goose.ProviderSetID) (_ []outGroup, imports ma inputs: in, outputs: out, }) - case *goose.IfaceBinding: + case *wire.IfaceBinding: i, ok := inputVisited.At(p.Provided).(int) if !ok { stk = append(stk, curr, p.Provided) diff --git a/internal/goose/testdata/NiladicValue/foo/goose.go b/internal/goose/testdata/NiladicValue/foo/goose.go deleted file mode 100644 index da9be36..0000000 --- a/internal/goose/testdata/NiladicValue/foo/goose.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2018 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//+build gooseinject - -package main - -import ( - "github.com/google/go-cloud/goose" -) - -func injectedMessage() string { - panic(goose.Build(goose.Value("Hello, World!"))) -} diff --git a/internal/goose/testdata/ValueChain/foo/goose.go b/internal/goose/testdata/ValueChain/foo/goose.go deleted file mode 100644 index 35e40ba..0000000 --- a/internal/goose/testdata/ValueChain/foo/goose.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2018 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//+build gooseinject - -package main - -import ( - "github.com/google/go-cloud/goose" -) - -func injectFooBar() FooBar { - panic(goose.Build(Set)) -} diff --git a/internal/goose/testdata/VarValue/foo/goose.go b/internal/goose/testdata/VarValue/foo/goose.go deleted file mode 100644 index b4286aa..0000000 --- a/internal/goose/testdata/VarValue/foo/goose.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2018 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//+build gooseinject - -package main - -import ( - "github.com/google/go-cloud/goose" -) - -func injectedMessage() string { - panic(goose.Build(goose.Value(msg))) -} diff --git a/internal/goose/analyze.go b/internal/wire/analyze.go similarity index 99% rename from internal/goose/analyze.go rename to internal/wire/analyze.go index b2d32ed..7aeefe2 100644 --- a/internal/goose/analyze.go +++ b/internal/wire/analyze.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package goose +package wire import ( "fmt" diff --git a/internal/goose/copyast.go b/internal/wire/copyast.go similarity index 99% rename from internal/goose/copyast.go rename to internal/wire/copyast.go index 1daef29..c49c8b5 100644 --- a/internal/goose/copyast.go +++ b/internal/wire/copyast.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package goose +package wire import ( "fmt" diff --git a/internal/goose/parse.go b/internal/wire/parse.go similarity index 94% rename from internal/goose/parse.go rename to internal/wire/parse.go index 5c5742d..6b07b3c 100644 --- a/internal/goose/parse.go +++ b/internal/wire/parse.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package goose +package wire import ( "errors" @@ -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.Build that + // Pos is the position of the call to wire.NewSet or wire.Build that // created the set. Pos token.Pos // PkgPath is the import path of the package that declared this set. @@ -110,7 +110,7 @@ type Value struct { // Out is the type this value produces. Out types.Type - // expr is the expression passed to goose.Value. + // expr is the expression passed to wire.Value. expr ast.Expr // info is the type info for the expression. @@ -177,7 +177,7 @@ func (id ProviderSetID) String() string { return strconv.Quote(id.ImportPath) + "." + id.VarName } -// objectCache is a lazily evaluated mapping of objects to goose structures. +// objectCache is a lazily evaluated mapping of objects to Wire structures. type objectCache struct { prog *loader.Program objects map[objRef]interface{} // *Provider, *ProviderSet, *IfaceBinding, or *Value @@ -195,7 +195,7 @@ func newObjectCache(prog *loader.Program) *objectCache { } } -// get converts a Go object into a goose structure. It may return a +// get converts a Go object into a Wire structure. It may return a // *Provider, a structProviderPair, an *IfaceBinding, a *ProviderSet, // or a *Value. func (oc *objectCache) get(obj types.Object) (interface{}, error) { @@ -256,7 +256,7 @@ func (oc *objectCache) varDecl(obj *types.Var) *ast.ValueSpec { return nil } -// processExpr converts an expression into a goose structure. It may +// processExpr converts an expression into a Wire structure. It may // return a *Provider, a structProviderPair, an *IfaceBinding, a // *ProviderSet, or a *Value. func (oc *objectCache) processExpr(pkg *loader.PackageInfo, expr ast.Expr) (interface{}, error) { @@ -271,7 +271,7 @@ func (oc *objectCache) processExpr(pkg *loader.PackageInfo, expr ast.Expr) (inte } if call, ok := expr.(*ast.CallExpr); ok { fnObj := qualifiedIdentObject(&pkg.Info, call.Fun) - if fnObj == nil || !isGooseImport(fnObj.Pkg().Path()) { + if fnObj == nil || !isWireImport(fnObj.Pkg().Path()) { return nil, fmt.Errorf("%v: unknown pattern", exprPos) } switch fnObj.Name() { @@ -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.Build. + // Assumes that call.Fun is wire.NewSet or wire.Build. pset := &ProviderSet{ Pos: call.Pos(), @@ -488,9 +488,9 @@ func processStructProvider(fset *token.FileSet, typeName *types.TypeName) (*Prov return provider, nil } -// processBind creates an interface binding from a goose.Bind call. +// processBind creates an interface binding from a wire.Bind call. func processBind(fset *token.FileSet, info *types.Info, call *ast.CallExpr) (*IfaceBinding, error) { - // Assumes that call.Fun is goose.Bind. + // Assumes that call.Fun is wire.Bind. if len(call.Args) != 2 { return nil, fmt.Errorf("%v: call to Bind takes exactly two arguments", fset.Position(call.Pos())) @@ -519,9 +519,9 @@ func processBind(fset *token.FileSet, info *types.Info, call *ast.CallExpr) (*If }, nil } -// processValue creates a value from a goose.Value call. +// processValue creates a value from a wire.Value call. func processValue(fset *token.FileSet, info *types.Info, call *ast.CallExpr) (*Value, error) { - // Assumes that call.Fun is goose.Value. + // Assumes that call.Fun is wire.Value. if len(call.Args) != 1 { return nil, fmt.Errorf("%v: call to Value takes exactly one argument", fset.Position(call.Pos())) @@ -562,7 +562,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.Build call. It returns nil if +// injector template, returning the wire.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 { @@ -604,17 +604,17 @@ func isInjector(info *types.Info, fn *ast.FuncDecl) *ast.CallExpr { return nil } buildObj := qualifiedIdentObject(info, buildCall.Fun) - if !isGooseImport(buildObj.Pkg().Path()) || buildObj.Name() != "Build" { + if !isWireImport(buildObj.Pkg().Path()) || buildObj.Name() != "Build" { return nil } return buildCall } -func isGooseImport(path string) bool { +func isWireImport(path string) bool { // TODO(light): This is depending on details of the current loader. const vendorPart = "vendor/" if i := strings.LastIndex(path, vendorPart); i != -1 && (i == 0 || path[i-1] == '/') { path = path[i+len(vendorPart):] } - return path == "github.com/google/go-cloud/goose" + return path == "github.com/google/go-cloud/wire" } diff --git a/internal/goose/testdata/Chain/foo/foo.go b/internal/wire/testdata/Chain/foo/foo.go similarity index 93% rename from internal/goose/testdata/Chain/foo/foo.go rename to internal/wire/testdata/Chain/foo/foo.go index 05c025e..1f7046c 100644 --- a/internal/goose/testdata/Chain/foo/foo.go +++ b/internal/wire/testdata/Chain/foo/foo.go @@ -17,7 +17,7 @@ package main import ( "fmt" - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func main() { @@ -27,7 +27,7 @@ func main() { type Foo int type FooBar int -var Set = goose.NewSet( +var Set = wire.NewSet( provideFoo, provideFooBar) diff --git a/internal/goose/testdata/Chain/foo/foo_goose.go b/internal/wire/testdata/Chain/foo/wire.go similarity index 88% rename from internal/goose/testdata/Chain/foo/foo_goose.go rename to internal/wire/testdata/Chain/foo/wire.go index 35e40ba..55ba464 100644 --- a/internal/goose/testdata/Chain/foo/foo_goose.go +++ b/internal/wire/testdata/Chain/foo/wire.go @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build gooseinject +//+build wireinject package main import ( - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func injectFooBar() FooBar { - panic(goose.Build(Set)) + panic(wire.Build(Set)) } diff --git a/internal/goose/testdata/Chain/out.txt b/internal/wire/testdata/Chain/out.txt similarity index 100% rename from internal/goose/testdata/Chain/out.txt rename to internal/wire/testdata/Chain/out.txt diff --git a/internal/goose/testdata/Chain/pkg b/internal/wire/testdata/Chain/pkg similarity index 100% rename from internal/goose/testdata/Chain/pkg rename to internal/wire/testdata/Chain/pkg diff --git a/internal/goose/testdata/Cleanup/foo/foo.go b/internal/wire/testdata/Cleanup/foo/foo.go similarity index 100% rename from internal/goose/testdata/Cleanup/foo/foo.go rename to internal/wire/testdata/Cleanup/foo/foo.go diff --git a/internal/goose/testdata/Cleanup/foo/goose.go b/internal/wire/testdata/Cleanup/foo/wire.go similarity index 86% rename from internal/goose/testdata/Cleanup/foo/goose.go rename to internal/wire/testdata/Cleanup/foo/wire.go index 6b37bc1..281a4d6 100644 --- a/internal/goose/testdata/Cleanup/foo/goose.go +++ b/internal/wire/testdata/Cleanup/foo/wire.go @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build gooseinject +//+build wireinject package main import ( - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func injectBar() (*Bar, func()) { - panic(goose.Build(provideFoo, provideBar)) + panic(wire.Build(provideFoo, provideBar)) } diff --git a/internal/goose/testdata/Cleanup/out.txt b/internal/wire/testdata/Cleanup/out.txt similarity index 100% rename from internal/goose/testdata/Cleanup/out.txt rename to internal/wire/testdata/Cleanup/out.txt diff --git a/internal/goose/testdata/Cleanup/pkg b/internal/wire/testdata/Cleanup/pkg similarity index 100% rename from internal/goose/testdata/Cleanup/pkg rename to internal/wire/testdata/Cleanup/pkg diff --git a/internal/goose/testdata/CopyOtherDecls/foo/foo.go b/internal/wire/testdata/CopyOtherDecls/foo/foo.go similarity index 84% rename from internal/goose/testdata/CopyOtherDecls/foo/foo.go rename to internal/wire/testdata/CopyOtherDecls/foo/foo.go index 6293ec2..fc33212 100644 --- a/internal/goose/testdata/CopyOtherDecls/foo/foo.go +++ b/internal/wire/testdata/CopyOtherDecls/foo/foo.go @@ -12,17 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build gooseinject +//+build wireinject // All of the declarations are in one file. -// goose should copy non-injectors over, preserving imports. +// gowire should copy non-injectors over, preserving imports. package main import ( "fmt" - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func main() { @@ -35,5 +35,5 @@ func provideMessage() string { } func injectedMessage() string { - panic(goose.Build(provideMessage)) + panic(wire.Build(provideMessage)) } diff --git a/internal/goose/testdata/CopyOtherDecls/out.txt b/internal/wire/testdata/CopyOtherDecls/out.txt similarity index 100% rename from internal/goose/testdata/CopyOtherDecls/out.txt rename to internal/wire/testdata/CopyOtherDecls/out.txt diff --git a/internal/goose/testdata/CopyOtherDecls/pkg b/internal/wire/testdata/CopyOtherDecls/pkg similarity index 100% rename from internal/goose/testdata/CopyOtherDecls/pkg rename to internal/wire/testdata/CopyOtherDecls/pkg diff --git a/internal/goose/testdata/EmptyVar/foo/foo.go b/internal/wire/testdata/EmptyVar/foo/foo.go similarity index 100% rename from internal/goose/testdata/EmptyVar/foo/foo.go rename to internal/wire/testdata/EmptyVar/foo/foo.go diff --git a/internal/goose/testdata/EmptyVar/foo/goose.go b/internal/wire/testdata/EmptyVar/foo/wire.go similarity index 88% rename from internal/goose/testdata/EmptyVar/foo/goose.go rename to internal/wire/testdata/EmptyVar/foo/wire.go index 55b232e..694633f 100644 --- a/internal/goose/testdata/EmptyVar/foo/goose.go +++ b/internal/wire/testdata/EmptyVar/foo/wire.go @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build gooseinject +//+build wireinject package main import ( - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func injectedMessage() string { - panic(goose.Build(myFakeSet)) + panic(wire.Build(myFakeSet)) } diff --git a/internal/goose/testdata/EmptyVar/out.txt b/internal/wire/testdata/EmptyVar/out.txt similarity index 100% rename from internal/goose/testdata/EmptyVar/out.txt rename to internal/wire/testdata/EmptyVar/out.txt diff --git a/internal/goose/testdata/EmptyVar/pkg b/internal/wire/testdata/EmptyVar/pkg similarity index 100% rename from internal/goose/testdata/EmptyVar/pkg rename to internal/wire/testdata/EmptyVar/pkg diff --git a/internal/goose/testdata/ExportedValue/bar/bar.go b/internal/wire/testdata/ExportedValue/bar/bar.go similarity index 89% rename from internal/goose/testdata/ExportedValue/bar/bar.go rename to internal/wire/testdata/ExportedValue/bar/bar.go index 9507812..f076440 100644 --- a/internal/goose/testdata/ExportedValue/bar/bar.go +++ b/internal/wire/testdata/ExportedValue/bar/bar.go @@ -14,8 +14,8 @@ package bar -import "github.com/google/go-cloud/goose" +import "github.com/google/go-cloud/wire" -var Value = goose.Value(PublicMsg) +var Value = wire.Value(PublicMsg) var PublicMsg = "Hello, World!" diff --git a/internal/goose/testdata/ExportedValue/foo/foo.go b/internal/wire/testdata/ExportedValue/foo/foo.go similarity index 100% rename from internal/goose/testdata/ExportedValue/foo/foo.go rename to internal/wire/testdata/ExportedValue/foo/foo.go diff --git a/internal/goose/testdata/UnexportedValue/foo/goose.go b/internal/wire/testdata/ExportedValue/foo/wire.go similarity index 88% rename from internal/goose/testdata/UnexportedValue/foo/goose.go rename to internal/wire/testdata/ExportedValue/foo/wire.go index a37e0ce..f31b925 100644 --- a/internal/goose/testdata/UnexportedValue/foo/goose.go +++ b/internal/wire/testdata/ExportedValue/foo/wire.go @@ -12,15 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build gooseinject +//+build wireinject package main import ( "bar" - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func injectedMessage() string { - panic(goose.Build(bar.Value)) + panic(wire.Build(bar.Value)) } diff --git a/internal/goose/testdata/ExportedValue/out.txt b/internal/wire/testdata/ExportedValue/out.txt similarity index 100% rename from internal/goose/testdata/ExportedValue/out.txt rename to internal/wire/testdata/ExportedValue/out.txt diff --git a/internal/goose/testdata/ExportedValue/pkg b/internal/wire/testdata/ExportedValue/pkg similarity index 100% rename from internal/goose/testdata/ExportedValue/pkg rename to internal/wire/testdata/ExportedValue/pkg diff --git a/internal/goose/testdata/ExportedValueDifferentPackage/bar/bar.go b/internal/wire/testdata/ExportedValueDifferentPackage/bar/bar.go similarity index 89% rename from internal/goose/testdata/ExportedValueDifferentPackage/bar/bar.go rename to internal/wire/testdata/ExportedValueDifferentPackage/bar/bar.go index 4e7b163..634e6ca 100644 --- a/internal/goose/testdata/ExportedValueDifferentPackage/bar/bar.go +++ b/internal/wire/testdata/ExportedValueDifferentPackage/bar/bar.go @@ -17,7 +17,7 @@ package bar import ( "os" - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) -var Value = goose.Value(os.Stdout) +var Value = wire.Value(os.Stdout) diff --git a/internal/goose/testdata/ExportedValueDifferentPackage/foo/foo.go b/internal/wire/testdata/ExportedValueDifferentPackage/foo/foo.go similarity index 100% rename from internal/goose/testdata/ExportedValueDifferentPackage/foo/foo.go rename to internal/wire/testdata/ExportedValueDifferentPackage/foo/foo.go diff --git a/internal/goose/testdata/ExportedValueDifferentPackage/foo/goose.go b/internal/wire/testdata/ExportedValueDifferentPackage/foo/wire.go similarity index 88% rename from internal/goose/testdata/ExportedValueDifferentPackage/foo/goose.go rename to internal/wire/testdata/ExportedValueDifferentPackage/foo/wire.go index d8a4a2f..f9c12a1 100644 --- a/internal/goose/testdata/ExportedValueDifferentPackage/foo/goose.go +++ b/internal/wire/testdata/ExportedValueDifferentPackage/foo/wire.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build gooseinject +//+build wireinject package main @@ -20,9 +20,9 @@ import ( "os" "bar" - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func injectedFile() *os.File { - panic(goose.Build(bar.Value)) + panic(wire.Build(bar.Value)) } diff --git a/internal/goose/testdata/ExportedValueDifferentPackage/out.txt b/internal/wire/testdata/ExportedValueDifferentPackage/out.txt similarity index 100% rename from internal/goose/testdata/ExportedValueDifferentPackage/out.txt rename to internal/wire/testdata/ExportedValueDifferentPackage/out.txt diff --git a/internal/goose/testdata/ExportedValueDifferentPackage/pkg b/internal/wire/testdata/ExportedValueDifferentPackage/pkg similarity index 100% rename from internal/goose/testdata/ExportedValueDifferentPackage/pkg rename to internal/wire/testdata/ExportedValueDifferentPackage/pkg diff --git a/internal/goose/testdata/ImportedInterfaceBinding/bar/bar.go b/internal/wire/testdata/ImportedInterfaceBinding/bar/bar.go similarity index 88% rename from internal/goose/testdata/ImportedInterfaceBinding/bar/bar.go rename to internal/wire/testdata/ImportedInterfaceBinding/bar/bar.go index cbd9e16..4a053fc 100644 --- a/internal/goose/testdata/ImportedInterfaceBinding/bar/bar.go +++ b/internal/wire/testdata/ImportedInterfaceBinding/bar/bar.go @@ -18,7 +18,7 @@ import ( "fmt" "foo" - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func main() { @@ -37,6 +37,6 @@ func provideBar() *Bar { return b } -var Set = goose.NewSet( +var Set = wire.NewSet( provideBar, - goose.Bind((*foo.Fooer)(nil), (*Bar)(nil))) + wire.Bind((*foo.Fooer)(nil), (*Bar)(nil))) diff --git a/internal/goose/testdata/ImportedInterfaceBinding/bar/goose.go b/internal/wire/testdata/ImportedInterfaceBinding/bar/wire.go similarity index 88% rename from internal/goose/testdata/ImportedInterfaceBinding/bar/goose.go rename to internal/wire/testdata/ImportedInterfaceBinding/bar/wire.go index 06d5aaf..4bfcf4f 100644 --- a/internal/goose/testdata/ImportedInterfaceBinding/bar/goose.go +++ b/internal/wire/testdata/ImportedInterfaceBinding/bar/wire.go @@ -12,15 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build gooseinject +//+build wireinject package main import ( - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" "foo" ) func injectFooer() foo.Fooer { - panic(goose.Build(Set)) + panic(wire.Build(Set)) } diff --git a/internal/goose/testdata/ImportedInterfaceBinding/foo/foo.go b/internal/wire/testdata/ImportedInterfaceBinding/foo/foo.go similarity index 100% rename from internal/goose/testdata/ImportedInterfaceBinding/foo/foo.go rename to internal/wire/testdata/ImportedInterfaceBinding/foo/foo.go diff --git a/internal/goose/testdata/ImportedInterfaceBinding/out.txt b/internal/wire/testdata/ImportedInterfaceBinding/out.txt similarity index 100% rename from internal/goose/testdata/ImportedInterfaceBinding/out.txt rename to internal/wire/testdata/ImportedInterfaceBinding/out.txt diff --git a/internal/goose/testdata/ImportedInterfaceBinding/pkg b/internal/wire/testdata/ImportedInterfaceBinding/pkg similarity index 100% rename from internal/goose/testdata/ImportedInterfaceBinding/pkg rename to internal/wire/testdata/ImportedInterfaceBinding/pkg diff --git a/internal/goose/testdata/InjectInput/foo/foo.go b/internal/wire/testdata/InjectInput/foo/foo.go similarity index 93% rename from internal/goose/testdata/InjectInput/foo/foo.go rename to internal/wire/testdata/InjectInput/foo/foo.go index 6e66a33..1496409 100644 --- a/internal/goose/testdata/InjectInput/foo/foo.go +++ b/internal/wire/testdata/InjectInput/foo/foo.go @@ -17,7 +17,7 @@ package main import ( "fmt" - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func main() { @@ -28,7 +28,7 @@ type Foo int type Bar int type FooBar int -var Set = goose.NewSet( +var Set = wire.NewSet( provideBar, provideFooBar) diff --git a/internal/goose/testdata/InjectInput/foo/foo_goose.go b/internal/wire/testdata/InjectInput/foo/wire.go similarity index 88% rename from internal/goose/testdata/InjectInput/foo/foo_goose.go rename to internal/wire/testdata/InjectInput/foo/wire.go index c08a9a3..32def6e 100644 --- a/internal/goose/testdata/InjectInput/foo/foo_goose.go +++ b/internal/wire/testdata/InjectInput/foo/wire.go @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build gooseinject +//+build wireinject package main import ( - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func injectFooBar(foo Foo) FooBar { - panic(goose.Build(Set)) + panic(wire.Build(Set)) } diff --git a/internal/goose/testdata/InjectInput/out.txt b/internal/wire/testdata/InjectInput/out.txt similarity index 100% rename from internal/goose/testdata/InjectInput/out.txt rename to internal/wire/testdata/InjectInput/out.txt diff --git a/internal/goose/testdata/InjectInput/pkg b/internal/wire/testdata/InjectInput/pkg similarity index 100% rename from internal/goose/testdata/InjectInput/pkg rename to internal/wire/testdata/InjectInput/pkg diff --git a/internal/goose/testdata/InjectInputConflict/foo/foo.go b/internal/wire/testdata/InjectInputConflict/foo/foo.go similarity index 94% rename from internal/goose/testdata/InjectInputConflict/foo/foo.go rename to internal/wire/testdata/InjectInputConflict/foo/foo.go index 53098c2..a79cafb 100644 --- a/internal/goose/testdata/InjectInputConflict/foo/foo.go +++ b/internal/wire/testdata/InjectInputConflict/foo/foo.go @@ -17,7 +17,7 @@ package main import ( "fmt" - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func main() { @@ -30,7 +30,7 @@ func main() { type Foo int type Bar int -var Set = goose.NewSet( +var Set = wire.NewSet( provideFoo, provideBar) diff --git a/internal/goose/testdata/InjectInputConflict/foo/foo_goose.go b/internal/wire/testdata/InjectInputConflict/foo/wire.go similarity index 88% rename from internal/goose/testdata/InjectInputConflict/foo/foo_goose.go rename to internal/wire/testdata/InjectInputConflict/foo/wire.go index 91d9c3f..f316ce1 100644 --- a/internal/goose/testdata/InjectInputConflict/foo/foo_goose.go +++ b/internal/wire/testdata/InjectInputConflict/foo/wire.go @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build gooseinject +//+build wireinject package main import ( - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func injectBar(foo Foo) Bar { - panic(goose.Build(Set)) + panic(wire.Build(Set)) } diff --git a/internal/goose/testdata/InjectInputConflict/out.txt b/internal/wire/testdata/InjectInputConflict/out.txt similarity index 100% rename from internal/goose/testdata/InjectInputConflict/out.txt rename to internal/wire/testdata/InjectInputConflict/out.txt diff --git a/internal/goose/testdata/InjectInputConflict/pkg b/internal/wire/testdata/InjectInputConflict/pkg similarity index 100% rename from internal/goose/testdata/InjectInputConflict/pkg rename to internal/wire/testdata/InjectInputConflict/pkg diff --git a/internal/goose/testdata/InterfaceBinding/foo/foo.go b/internal/wire/testdata/InterfaceBinding/foo/foo.go similarity index 89% rename from internal/goose/testdata/InterfaceBinding/foo/foo.go rename to internal/wire/testdata/InterfaceBinding/foo/foo.go index 5ff809f..475e8ce 100644 --- a/internal/goose/testdata/InterfaceBinding/foo/foo.go +++ b/internal/wire/testdata/InterfaceBinding/foo/foo.go @@ -17,7 +17,7 @@ package main import ( "fmt" - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func main() { @@ -40,6 +40,6 @@ func provideBar() *Bar { return b } -var Set = goose.NewSet( +var Set = wire.NewSet( provideBar, - goose.Bind((*Fooer)(nil), (*Bar)(nil))) + wire.Bind((*Fooer)(nil), (*Bar)(nil))) diff --git a/internal/goose/testdata/InterfaceBinding/foo/foo_goose.go b/internal/wire/testdata/InterfaceBinding/foo/wire.go similarity index 88% rename from internal/goose/testdata/InterfaceBinding/foo/foo_goose.go rename to internal/wire/testdata/InterfaceBinding/foo/wire.go index 3b3fbf6..6aa286a 100644 --- a/internal/goose/testdata/InterfaceBinding/foo/foo_goose.go +++ b/internal/wire/testdata/InterfaceBinding/foo/wire.go @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build gooseinject +//+build wireinject package main import ( - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func injectFooer() Fooer { - panic(goose.Build(Set)) + panic(wire.Build(Set)) } diff --git a/internal/goose/testdata/InterfaceBinding/out.txt b/internal/wire/testdata/InterfaceBinding/out.txt similarity index 100% rename from internal/goose/testdata/InterfaceBinding/out.txt rename to internal/wire/testdata/InterfaceBinding/out.txt diff --git a/internal/goose/testdata/InterfaceBinding/pkg b/internal/wire/testdata/InterfaceBinding/pkg similarity index 100% rename from internal/goose/testdata/InterfaceBinding/pkg rename to internal/wire/testdata/InterfaceBinding/pkg diff --git a/internal/goose/testdata/InterfaceBindingReuse/foo/foo.go b/internal/wire/testdata/InterfaceBindingReuse/foo/foo.go similarity index 100% rename from internal/goose/testdata/InterfaceBindingReuse/foo/foo.go rename to internal/wire/testdata/InterfaceBindingReuse/foo/foo.go diff --git a/internal/goose/testdata/InterfaceBindingReuse/foo/foo_goose.go b/internal/wire/testdata/InterfaceBindingReuse/foo/wire.go similarity index 84% rename from internal/goose/testdata/InterfaceBindingReuse/foo/foo_goose.go rename to internal/wire/testdata/InterfaceBindingReuse/foo/wire.go index 7c00827..e0a6143 100644 --- a/internal/goose/testdata/InterfaceBindingReuse/foo/foo_goose.go +++ b/internal/wire/testdata/InterfaceBindingReuse/foo/wire.go @@ -12,17 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build gooseinject +//+build wireinject package main import ( - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func injectFooBar() FooBar { - panic(goose.Build( + panic(wire.Build( provideBar, provideFooBar, - goose.Bind((*Fooer)(nil), (*Bar)(nil)))) + wire.Bind((*Fooer)(nil), (*Bar)(nil)))) } diff --git a/internal/goose/testdata/InterfaceBindingReuse/out.txt b/internal/wire/testdata/InterfaceBindingReuse/out.txt similarity index 100% rename from internal/goose/testdata/InterfaceBindingReuse/out.txt rename to internal/wire/testdata/InterfaceBindingReuse/out.txt diff --git a/internal/goose/testdata/InterfaceBindingReuse/pkg b/internal/wire/testdata/InterfaceBindingReuse/pkg similarity index 100% rename from internal/goose/testdata/InterfaceBindingReuse/pkg rename to internal/wire/testdata/InterfaceBindingReuse/pkg diff --git a/internal/goose/testdata/NamingWorstCase/foo/foo.go b/internal/wire/testdata/NamingWorstCase/foo/foo.go similarity index 100% rename from internal/goose/testdata/NamingWorstCase/foo/foo.go rename to internal/wire/testdata/NamingWorstCase/foo/foo.go diff --git a/internal/goose/testdata/NamingWorstCase/foo/goose.go b/internal/wire/testdata/NamingWorstCase/foo/wire.go similarity index 89% rename from internal/goose/testdata/NamingWorstCase/foo/goose.go rename to internal/wire/testdata/NamingWorstCase/foo/wire.go index c4f22c5..f27f646 100644 --- a/internal/goose/testdata/NamingWorstCase/foo/goose.go +++ b/internal/wire/testdata/NamingWorstCase/foo/wire.go @@ -12,16 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build gooseinject +//+build wireinject package main import ( stdcontext "context" - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func inject(context stdcontext.Context, err struct{}) (context, error) { - panic(goose.Build(provide)) + panic(wire.Build(provide)) } diff --git a/internal/goose/testdata/NamingWorstCase/out.txt b/internal/wire/testdata/NamingWorstCase/out.txt similarity index 100% rename from internal/goose/testdata/NamingWorstCase/out.txt rename to internal/wire/testdata/NamingWorstCase/out.txt diff --git a/internal/goose/testdata/NamingWorstCase/pkg b/internal/wire/testdata/NamingWorstCase/pkg similarity index 100% rename from internal/goose/testdata/NamingWorstCase/pkg rename to internal/wire/testdata/NamingWorstCase/pkg diff --git a/internal/goose/testdata/NamingWorstCaseAllInOne/foo/foo.go b/internal/wire/testdata/NamingWorstCaseAllInOne/foo/foo.go similarity index 94% rename from internal/goose/testdata/NamingWorstCaseAllInOne/foo/foo.go rename to internal/wire/testdata/NamingWorstCaseAllInOne/foo/foo.go index 2255582..0b01abe 100644 --- a/internal/goose/testdata/NamingWorstCaseAllInOne/foo/foo.go +++ b/internal/wire/testdata/NamingWorstCaseAllInOne/foo/foo.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build gooseinject +//+build wireinject // This file is specifically designed to cause issues with copying the // AST, particularly with the identifier "context". @@ -25,7 +25,7 @@ import ( "os" "reflect" - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) type context struct{} @@ -51,7 +51,7 @@ func Provide(context2 stdcontext.Context) (context, error) { } func inject(context stdcontext.Context, err struct{}) (context, error) { - panic(goose.Build(Provide)) + panic(wire.Build(Provide)) } func (context) Provide() { diff --git a/internal/goose/testdata/NamingWorstCaseAllInOne/out.txt b/internal/wire/testdata/NamingWorstCaseAllInOne/out.txt similarity index 100% rename from internal/goose/testdata/NamingWorstCaseAllInOne/out.txt rename to internal/wire/testdata/NamingWorstCaseAllInOne/out.txt diff --git a/internal/goose/testdata/NamingWorstCaseAllInOne/pkg b/internal/wire/testdata/NamingWorstCaseAllInOne/pkg similarity index 100% rename from internal/goose/testdata/NamingWorstCaseAllInOne/pkg rename to internal/wire/testdata/NamingWorstCaseAllInOne/pkg diff --git a/internal/goose/testdata/NiladicIdentity/foo/foo.go b/internal/wire/testdata/NiladicIdentity/foo/foo.go similarity index 100% rename from internal/goose/testdata/NiladicIdentity/foo/foo.go rename to internal/wire/testdata/NiladicIdentity/foo/foo.go diff --git a/internal/goose/testdata/NiladicIdentity/foo/foo_goose.go b/internal/wire/testdata/NiladicIdentity/foo/wire.go similarity index 87% rename from internal/goose/testdata/NiladicIdentity/foo/foo_goose.go rename to internal/wire/testdata/NiladicIdentity/foo/wire.go index 52fa33c..7c1e5a8 100644 --- a/internal/goose/testdata/NiladicIdentity/foo/foo_goose.go +++ b/internal/wire/testdata/NiladicIdentity/foo/wire.go @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build gooseinject +//+build wireinject package main import ( - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func injectedMessage() string { - panic(goose.Build(provideMessage)) + panic(wire.Build(provideMessage)) } diff --git a/internal/goose/testdata/NiladicIdentity/out.txt b/internal/wire/testdata/NiladicIdentity/out.txt similarity index 100% rename from internal/goose/testdata/NiladicIdentity/out.txt rename to internal/wire/testdata/NiladicIdentity/out.txt diff --git a/internal/goose/testdata/NiladicIdentity/pkg b/internal/wire/testdata/NiladicIdentity/pkg similarity index 100% rename from internal/goose/testdata/NiladicIdentity/pkg rename to internal/wire/testdata/NiladicIdentity/pkg diff --git a/internal/goose/testdata/NiladicValue/foo/foo.go b/internal/wire/testdata/NiladicValue/foo/foo.go similarity index 100% rename from internal/goose/testdata/NiladicValue/foo/foo.go rename to internal/wire/testdata/NiladicValue/foo/foo.go diff --git a/internal/wire/testdata/NiladicValue/foo/wire.go b/internal/wire/testdata/NiladicValue/foo/wire.go new file mode 100644 index 0000000..d8165ee --- /dev/null +++ b/internal/wire/testdata/NiladicValue/foo/wire.go @@ -0,0 +1,25 @@ +// Copyright 2018 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//+build wireinject + +package main + +import ( + "github.com/google/go-cloud/wire" +) + +func injectedMessage() string { + panic(wire.Build(wire.Value("Hello, World!"))) +} diff --git a/internal/goose/testdata/NiladicValue/out.txt b/internal/wire/testdata/NiladicValue/out.txt similarity index 100% rename from internal/goose/testdata/NiladicValue/out.txt rename to internal/wire/testdata/NiladicValue/out.txt diff --git a/internal/goose/testdata/NiladicValue/pkg b/internal/wire/testdata/NiladicValue/pkg similarity index 100% rename from internal/goose/testdata/NiladicValue/pkg rename to internal/wire/testdata/NiladicValue/pkg diff --git a/internal/goose/testdata/NoImplicitInterface/foo/foo.go b/internal/wire/testdata/NoImplicitInterface/foo/foo.go similarity index 100% rename from internal/goose/testdata/NoImplicitInterface/foo/foo.go rename to internal/wire/testdata/NoImplicitInterface/foo/foo.go diff --git a/internal/goose/testdata/NoImplicitInterface/foo/foo_goose.go b/internal/wire/testdata/NoImplicitInterface/foo/wire.go similarity index 87% rename from internal/goose/testdata/NoImplicitInterface/foo/foo_goose.go rename to internal/wire/testdata/NoImplicitInterface/foo/wire.go index 95386f5..b73bf41 100644 --- a/internal/goose/testdata/NoImplicitInterface/foo/foo_goose.go +++ b/internal/wire/testdata/NoImplicitInterface/foo/wire.go @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build gooseinject +//+build wireinject package main import ( - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func injectFooer() Fooer { - panic(goose.Build(provideBar)) + panic(wire.Build(provideBar)) } diff --git a/internal/goose/testdata/NoImplicitInterface/out.txt b/internal/wire/testdata/NoImplicitInterface/out.txt similarity index 100% rename from internal/goose/testdata/NoImplicitInterface/out.txt rename to internal/wire/testdata/NoImplicitInterface/out.txt diff --git a/internal/goose/testdata/NoImplicitInterface/pkg b/internal/wire/testdata/NoImplicitInterface/pkg similarity index 100% rename from internal/goose/testdata/NoImplicitInterface/pkg rename to internal/wire/testdata/NoImplicitInterface/pkg diff --git a/internal/goose/testdata/NoInjectParamNames/foo/foo.go b/internal/wire/testdata/NoInjectParamNames/foo/foo.go similarity index 100% rename from internal/goose/testdata/NoInjectParamNames/foo/foo.go rename to internal/wire/testdata/NoInjectParamNames/foo/foo.go diff --git a/internal/goose/testdata/NoInjectParamNames/foo/goose.go b/internal/wire/testdata/NoInjectParamNames/foo/wire.go similarity index 90% rename from internal/goose/testdata/NoInjectParamNames/foo/goose.go rename to internal/wire/testdata/NoInjectParamNames/foo/wire.go index 503eb65..354a705 100644 --- a/internal/goose/testdata/NoInjectParamNames/foo/goose.go +++ b/internal/wire/testdata/NoInjectParamNames/foo/wire.go @@ -12,19 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build gooseinject +//+build wireinject package main import ( stdcontext "context" - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) // The notable characteristic of this test is that there are no // parameter names on the inject stub. func inject(stdcontext.Context, struct{}) (context, error) { - panic(goose.Build(provide)) + panic(wire.Build(provide)) } diff --git a/internal/goose/testdata/NoInjectParamNames/out.txt b/internal/wire/testdata/NoInjectParamNames/out.txt similarity index 100% rename from internal/goose/testdata/NoInjectParamNames/out.txt rename to internal/wire/testdata/NoInjectParamNames/out.txt diff --git a/internal/goose/testdata/NoInjectParamNames/pkg b/internal/wire/testdata/NoInjectParamNames/pkg similarity index 100% rename from internal/goose/testdata/NoInjectParamNames/pkg rename to internal/wire/testdata/NoInjectParamNames/pkg diff --git a/internal/goose/testdata/NoopBuild/foo/foo.go b/internal/wire/testdata/NoopBuild/foo/foo.go similarity index 100% rename from internal/goose/testdata/NoopBuild/foo/foo.go rename to internal/wire/testdata/NoopBuild/foo/foo.go diff --git a/internal/goose/testdata/NoopBuild/out.txt b/internal/wire/testdata/NoopBuild/out.txt similarity index 100% rename from internal/goose/testdata/NoopBuild/out.txt rename to internal/wire/testdata/NoopBuild/out.txt diff --git a/internal/goose/testdata/NoopBuild/pkg b/internal/wire/testdata/NoopBuild/pkg similarity index 100% rename from internal/goose/testdata/NoopBuild/pkg rename to internal/wire/testdata/NoopBuild/pkg diff --git a/internal/goose/testdata/PartialCleanup/foo/foo.go b/internal/wire/testdata/PartialCleanup/foo/foo.go similarity index 100% rename from internal/goose/testdata/PartialCleanup/foo/foo.go rename to internal/wire/testdata/PartialCleanup/foo/foo.go diff --git a/internal/goose/testdata/PartialCleanup/foo/goose.go b/internal/wire/testdata/PartialCleanup/foo/wire.go similarity index 85% rename from internal/goose/testdata/PartialCleanup/foo/goose.go rename to internal/wire/testdata/PartialCleanup/foo/wire.go index be69e63..62dd47a 100644 --- a/internal/goose/testdata/PartialCleanup/foo/goose.go +++ b/internal/wire/testdata/PartialCleanup/foo/wire.go @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build gooseinject +//+build wireinject package main import ( - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func injectBaz() (Baz, func(), error) { - panic(goose.Build(provideFoo, provideBar, provideBaz)) + panic(wire.Build(provideFoo, provideBar, provideBaz)) } diff --git a/internal/goose/testdata/PartialCleanup/out.txt b/internal/wire/testdata/PartialCleanup/out.txt similarity index 100% rename from internal/goose/testdata/PartialCleanup/out.txt rename to internal/wire/testdata/PartialCleanup/out.txt diff --git a/internal/goose/testdata/PartialCleanup/pkg b/internal/wire/testdata/PartialCleanup/pkg similarity index 100% rename from internal/goose/testdata/PartialCleanup/pkg rename to internal/wire/testdata/PartialCleanup/pkg diff --git a/internal/goose/testdata/PkgImport/bar/bar.go b/internal/wire/testdata/PkgImport/bar/bar.go similarity index 100% rename from internal/goose/testdata/PkgImport/bar/bar.go rename to internal/wire/testdata/PkgImport/bar/bar.go diff --git a/internal/goose/testdata/PkgImport/foo/foo.go b/internal/wire/testdata/PkgImport/foo/foo.go similarity index 93% rename from internal/goose/testdata/PkgImport/foo/foo.go rename to internal/wire/testdata/PkgImport/foo/foo.go index e28e2d5..f5881a4 100644 --- a/internal/goose/testdata/PkgImport/foo/foo.go +++ b/internal/wire/testdata/PkgImport/foo/foo.go @@ -18,7 +18,7 @@ import ( "fmt" "bar" - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func main() { @@ -28,7 +28,7 @@ func main() { type Foo int type FooBar int -var Set = goose.NewSet( +var Set = wire.NewSet( provideFoo, bar.ProvideBar, provideFooBar) diff --git a/internal/goose/testdata/PkgImport/foo/foo_goose.go b/internal/wire/testdata/PkgImport/foo/wire.go similarity index 88% rename from internal/goose/testdata/PkgImport/foo/foo_goose.go rename to internal/wire/testdata/PkgImport/foo/wire.go index 35e40ba..55ba464 100644 --- a/internal/goose/testdata/PkgImport/foo/foo_goose.go +++ b/internal/wire/testdata/PkgImport/foo/wire.go @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build gooseinject +//+build wireinject package main import ( - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func injectFooBar() FooBar { - panic(goose.Build(Set)) + panic(wire.Build(Set)) } diff --git a/internal/goose/testdata/PkgImport/out.txt b/internal/wire/testdata/PkgImport/out.txt similarity index 100% rename from internal/goose/testdata/PkgImport/out.txt rename to internal/wire/testdata/PkgImport/out.txt diff --git a/internal/goose/testdata/PkgImport/pkg b/internal/wire/testdata/PkgImport/pkg similarity index 100% rename from internal/goose/testdata/PkgImport/pkg rename to internal/wire/testdata/PkgImport/pkg diff --git a/internal/goose/testdata/ReturnError/foo/foo.go b/internal/wire/testdata/ReturnError/foo/foo.go similarity index 93% rename from internal/goose/testdata/ReturnError/foo/foo.go rename to internal/wire/testdata/ReturnError/foo/foo.go index a476329..d846923 100644 --- a/internal/goose/testdata/ReturnError/foo/foo.go +++ b/internal/wire/testdata/ReturnError/foo/foo.go @@ -19,7 +19,7 @@ import ( "fmt" "strings" - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func main() { @@ -38,4 +38,4 @@ func provideFoo() (Foo, error) { return 42, errors.New("there is no Foo") } -var Set = goose.NewSet(provideFoo) +var Set = wire.NewSet(provideFoo) diff --git a/internal/goose/testdata/ReturnError/foo/foo_goose.go b/internal/wire/testdata/ReturnError/foo/wire.go similarity index 88% rename from internal/goose/testdata/ReturnError/foo/foo_goose.go rename to internal/wire/testdata/ReturnError/foo/wire.go index 0ebfb90..b181e34 100644 --- a/internal/goose/testdata/ReturnError/foo/foo_goose.go +++ b/internal/wire/testdata/ReturnError/foo/wire.go @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build gooseinject +//+build wireinject package main import ( - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func injectFoo() (Foo, error) { - panic(goose.Build(Set)) + panic(wire.Build(Set)) } diff --git a/internal/goose/testdata/ReturnError/out.txt b/internal/wire/testdata/ReturnError/out.txt similarity index 100% rename from internal/goose/testdata/ReturnError/out.txt rename to internal/wire/testdata/ReturnError/out.txt diff --git a/internal/goose/testdata/ReturnError/pkg b/internal/wire/testdata/ReturnError/pkg similarity index 100% rename from internal/goose/testdata/ReturnError/pkg rename to internal/wire/testdata/ReturnError/pkg diff --git a/internal/goose/testdata/Struct/foo/foo.go b/internal/wire/testdata/Struct/foo/foo.go similarity index 93% rename from internal/goose/testdata/Struct/foo/foo.go rename to internal/wire/testdata/Struct/foo/foo.go index 627bdfa..343ad37 100644 --- a/internal/goose/testdata/Struct/foo/foo.go +++ b/internal/wire/testdata/Struct/foo/foo.go @@ -17,7 +17,7 @@ package main import ( "fmt" - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func main() { @@ -41,7 +41,7 @@ func provideBar() Bar { return 1 } -var Set = goose.NewSet( +var Set = wire.NewSet( FooBar{}, provideFoo, provideBar) diff --git a/internal/goose/testdata/Struct/foo/goose.go b/internal/wire/testdata/Struct/foo/wire.go similarity index 88% rename from internal/goose/testdata/Struct/foo/goose.go rename to internal/wire/testdata/Struct/foo/wire.go index 35e40ba..55ba464 100644 --- a/internal/goose/testdata/Struct/foo/goose.go +++ b/internal/wire/testdata/Struct/foo/wire.go @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build gooseinject +//+build wireinject package main import ( - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func injectFooBar() FooBar { - panic(goose.Build(Set)) + panic(wire.Build(Set)) } diff --git a/internal/goose/testdata/Struct/out.txt b/internal/wire/testdata/Struct/out.txt similarity index 100% rename from internal/goose/testdata/Struct/out.txt rename to internal/wire/testdata/Struct/out.txt diff --git a/internal/goose/testdata/Struct/pkg b/internal/wire/testdata/Struct/pkg similarity index 100% rename from internal/goose/testdata/Struct/pkg rename to internal/wire/testdata/Struct/pkg diff --git a/internal/goose/testdata/StructPointer/foo/foo.go b/internal/wire/testdata/StructPointer/foo/foo.go similarity index 93% rename from internal/goose/testdata/StructPointer/foo/foo.go rename to internal/wire/testdata/StructPointer/foo/foo.go index 627bdfa..343ad37 100644 --- a/internal/goose/testdata/StructPointer/foo/foo.go +++ b/internal/wire/testdata/StructPointer/foo/foo.go @@ -17,7 +17,7 @@ package main import ( "fmt" - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func main() { @@ -41,7 +41,7 @@ func provideBar() Bar { return 1 } -var Set = goose.NewSet( +var Set = wire.NewSet( FooBar{}, provideFoo, provideBar) diff --git a/internal/goose/testdata/StructPointer/foo/goose.go b/internal/wire/testdata/StructPointer/foo/wire.go similarity index 88% rename from internal/goose/testdata/StructPointer/foo/goose.go rename to internal/wire/testdata/StructPointer/foo/wire.go index f64f20f..6cf4d85 100644 --- a/internal/goose/testdata/StructPointer/foo/goose.go +++ b/internal/wire/testdata/StructPointer/foo/wire.go @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build gooseinject +//+build wireinject package main import ( - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func injectFooBar() *FooBar { - panic(goose.Build(Set)) + panic(wire.Build(Set)) } diff --git a/internal/goose/testdata/StructPointer/out.txt b/internal/wire/testdata/StructPointer/out.txt similarity index 100% rename from internal/goose/testdata/StructPointer/out.txt rename to internal/wire/testdata/StructPointer/out.txt diff --git a/internal/goose/testdata/StructPointer/pkg b/internal/wire/testdata/StructPointer/pkg similarity index 100% rename from internal/goose/testdata/StructPointer/pkg rename to internal/wire/testdata/StructPointer/pkg diff --git a/internal/goose/testdata/TwoDeps/foo/foo.go b/internal/wire/testdata/TwoDeps/foo/foo.go similarity index 93% rename from internal/goose/testdata/TwoDeps/foo/foo.go rename to internal/wire/testdata/TwoDeps/foo/foo.go index 431d78d..1b1bea6 100644 --- a/internal/goose/testdata/TwoDeps/foo/foo.go +++ b/internal/wire/testdata/TwoDeps/foo/foo.go @@ -17,7 +17,7 @@ package main import ( "fmt" - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func main() { @@ -40,7 +40,7 @@ func provideFooBar(foo Foo, bar Bar) FooBar { return FooBar(foo) + FooBar(bar) } -var Set = goose.NewSet( +var Set = wire.NewSet( provideFoo, provideBar, provideFooBar) diff --git a/internal/goose/testdata/TwoDeps/foo/foo_goose.go b/internal/wire/testdata/TwoDeps/foo/wire.go similarity index 88% rename from internal/goose/testdata/TwoDeps/foo/foo_goose.go rename to internal/wire/testdata/TwoDeps/foo/wire.go index 35e40ba..55ba464 100644 --- a/internal/goose/testdata/TwoDeps/foo/foo_goose.go +++ b/internal/wire/testdata/TwoDeps/foo/wire.go @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build gooseinject +//+build wireinject package main import ( - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func injectFooBar() FooBar { - panic(goose.Build(Set)) + panic(wire.Build(Set)) } diff --git a/internal/goose/testdata/TwoDeps/out.txt b/internal/wire/testdata/TwoDeps/out.txt similarity index 100% rename from internal/goose/testdata/TwoDeps/out.txt rename to internal/wire/testdata/TwoDeps/out.txt diff --git a/internal/goose/testdata/TwoDeps/pkg b/internal/wire/testdata/TwoDeps/pkg similarity index 100% rename from internal/goose/testdata/TwoDeps/pkg rename to internal/wire/testdata/TwoDeps/pkg diff --git a/internal/goose/testdata/UnexportedValue/bar/bar.go b/internal/wire/testdata/UnexportedValue/bar/bar.go similarity index 89% rename from internal/goose/testdata/UnexportedValue/bar/bar.go rename to internal/wire/testdata/UnexportedValue/bar/bar.go index b19ed9a..112df61 100644 --- a/internal/goose/testdata/UnexportedValue/bar/bar.go +++ b/internal/wire/testdata/UnexportedValue/bar/bar.go @@ -14,8 +14,8 @@ package bar -import "github.com/google/go-cloud/goose" +import "github.com/google/go-cloud/wire" -var Value = goose.Value(privateMsg) +var Value = wire.Value(privateMsg) var privateMsg = "Hello, World!" diff --git a/internal/goose/testdata/UnexportedValue/foo/foo.go b/internal/wire/testdata/UnexportedValue/foo/foo.go similarity index 100% rename from internal/goose/testdata/UnexportedValue/foo/foo.go rename to internal/wire/testdata/UnexportedValue/foo/foo.go diff --git a/internal/goose/testdata/ExportedValue/foo/goose.go b/internal/wire/testdata/UnexportedValue/foo/wire.go similarity index 88% rename from internal/goose/testdata/ExportedValue/foo/goose.go rename to internal/wire/testdata/UnexportedValue/foo/wire.go index a37e0ce..f31b925 100644 --- a/internal/goose/testdata/ExportedValue/foo/goose.go +++ b/internal/wire/testdata/UnexportedValue/foo/wire.go @@ -12,15 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build gooseinject +//+build wireinject package main import ( "bar" - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func injectedMessage() string { - panic(goose.Build(bar.Value)) + panic(wire.Build(bar.Value)) } diff --git a/internal/goose/testdata/UnexportedValue/out.txt b/internal/wire/testdata/UnexportedValue/out.txt similarity index 100% rename from internal/goose/testdata/UnexportedValue/out.txt rename to internal/wire/testdata/UnexportedValue/out.txt diff --git a/internal/goose/testdata/UnexportedValue/pkg b/internal/wire/testdata/UnexportedValue/pkg similarity index 100% rename from internal/goose/testdata/UnexportedValue/pkg rename to internal/wire/testdata/UnexportedValue/pkg diff --git a/internal/goose/testdata/ValueChain/foo/foo.go b/internal/wire/testdata/ValueChain/foo/foo.go similarity index 90% rename from internal/goose/testdata/ValueChain/foo/foo.go rename to internal/wire/testdata/ValueChain/foo/foo.go index 19c1b37..7442bba 100644 --- a/internal/goose/testdata/ValueChain/foo/foo.go +++ b/internal/wire/testdata/ValueChain/foo/foo.go @@ -17,7 +17,7 @@ package main import ( "fmt" - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func main() { @@ -27,8 +27,8 @@ func main() { type Foo int type FooBar int -var Set = goose.NewSet( - goose.Value(Foo(41)), +var Set = wire.NewSet( + wire.Value(Foo(41)), provideFooBar) func provideFooBar(foo Foo) FooBar { diff --git a/internal/wire/testdata/ValueChain/foo/wire.go b/internal/wire/testdata/ValueChain/foo/wire.go new file mode 100644 index 0000000..55ba464 --- /dev/null +++ b/internal/wire/testdata/ValueChain/foo/wire.go @@ -0,0 +1,25 @@ +// Copyright 2018 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//+build wireinject + +package main + +import ( + "github.com/google/go-cloud/wire" +) + +func injectFooBar() FooBar { + panic(wire.Build(Set)) +} diff --git a/internal/goose/testdata/ValueChain/out.txt b/internal/wire/testdata/ValueChain/out.txt similarity index 100% rename from internal/goose/testdata/ValueChain/out.txt rename to internal/wire/testdata/ValueChain/out.txt diff --git a/internal/goose/testdata/ValueChain/pkg b/internal/wire/testdata/ValueChain/pkg similarity index 100% rename from internal/goose/testdata/ValueChain/pkg rename to internal/wire/testdata/ValueChain/pkg diff --git a/internal/goose/testdata/ValueConversion/foo/foo.go b/internal/wire/testdata/ValueConversion/foo/foo.go similarity index 100% rename from internal/goose/testdata/ValueConversion/foo/foo.go rename to internal/wire/testdata/ValueConversion/foo/foo.go diff --git a/internal/goose/testdata/ValueConversion/foo/goose.go b/internal/wire/testdata/ValueConversion/foo/wire.go similarity index 85% rename from internal/goose/testdata/ValueConversion/foo/goose.go rename to internal/wire/testdata/ValueConversion/foo/wire.go index 098740d..9178b74 100644 --- a/internal/goose/testdata/ValueConversion/foo/goose.go +++ b/internal/wire/testdata/ValueConversion/foo/wire.go @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build gooseinject +//+build wireinject package main import ( - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func injectedMessage() Foo { - panic(goose.Build(goose.Value(Foo("Hello, World!")))) + panic(wire.Build(wire.Value(Foo("Hello, World!")))) } diff --git a/internal/goose/testdata/ValueConversion/out.txt b/internal/wire/testdata/ValueConversion/out.txt similarity index 100% rename from internal/goose/testdata/ValueConversion/out.txt rename to internal/wire/testdata/ValueConversion/out.txt diff --git a/internal/goose/testdata/ValueConversion/pkg b/internal/wire/testdata/ValueConversion/pkg similarity index 100% rename from internal/goose/testdata/ValueConversion/pkg rename to internal/wire/testdata/ValueConversion/pkg diff --git a/internal/goose/testdata/VarValue/foo/foo.go b/internal/wire/testdata/VarValue/foo/foo.go similarity index 100% rename from internal/goose/testdata/VarValue/foo/foo.go rename to internal/wire/testdata/VarValue/foo/foo.go diff --git a/internal/wire/testdata/VarValue/foo/wire.go b/internal/wire/testdata/VarValue/foo/wire.go new file mode 100644 index 0000000..e8e749b --- /dev/null +++ b/internal/wire/testdata/VarValue/foo/wire.go @@ -0,0 +1,25 @@ +// Copyright 2018 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//+build wireinject + +package main + +import ( + "github.com/google/go-cloud/wire" +) + +func injectedMessage() string { + panic(wire.Build(wire.Value(msg))) +} diff --git a/internal/goose/testdata/VarValue/out.txt b/internal/wire/testdata/VarValue/out.txt similarity index 100% rename from internal/goose/testdata/VarValue/out.txt rename to internal/wire/testdata/VarValue/out.txt diff --git a/internal/goose/testdata/VarValue/pkg b/internal/wire/testdata/VarValue/pkg similarity index 100% rename from internal/goose/testdata/VarValue/pkg rename to internal/wire/testdata/VarValue/pkg diff --git a/internal/goose/testdata/Vendor/bar/dummy.go b/internal/wire/testdata/Vendor/bar/dummy.go similarity index 100% rename from internal/goose/testdata/Vendor/bar/dummy.go rename to internal/wire/testdata/Vendor/bar/dummy.go diff --git a/internal/goose/testdata/Vendor/foo/foo.go b/internal/wire/testdata/Vendor/foo/foo.go similarity index 100% rename from internal/goose/testdata/Vendor/foo/foo.go rename to internal/wire/testdata/Vendor/foo/foo.go diff --git a/internal/goose/testdata/Vendor/foo/vendor/bar/bar.go b/internal/wire/testdata/Vendor/foo/vendor/bar/bar.go similarity index 100% rename from internal/goose/testdata/Vendor/foo/vendor/bar/bar.go rename to internal/wire/testdata/Vendor/foo/vendor/bar/bar.go diff --git a/internal/goose/testdata/Vendor/foo/goose.go b/internal/wire/testdata/Vendor/foo/wire.go similarity index 87% rename from internal/goose/testdata/Vendor/foo/goose.go rename to internal/wire/testdata/Vendor/foo/wire.go index 4540ef8..2389188 100644 --- a/internal/goose/testdata/Vendor/foo/goose.go +++ b/internal/wire/testdata/Vendor/foo/wire.go @@ -12,15 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build gooseinject +//+build wireinject package main import ( "bar" - "github.com/google/go-cloud/goose" + "github.com/google/go-cloud/wire" ) func injectedMessage() string { - panic(goose.Build(bar.ProvideMessage)) + panic(wire.Build(bar.ProvideMessage)) } diff --git a/internal/goose/testdata/Vendor/out.txt b/internal/wire/testdata/Vendor/out.txt similarity index 100% rename from internal/goose/testdata/Vendor/out.txt rename to internal/wire/testdata/Vendor/out.txt diff --git a/internal/goose/testdata/Vendor/pkg b/internal/wire/testdata/Vendor/pkg similarity index 100% rename from internal/goose/testdata/Vendor/pkg rename to internal/wire/testdata/Vendor/pkg diff --git a/internal/goose/goose.go b/internal/wire/wire.go similarity index 98% rename from internal/goose/goose.go rename to internal/wire/wire.go index 69381b2..7e7ceab 100644 --- a/internal/goose/goose.go +++ b/internal/wire/wire.go @@ -12,9 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package goose provides compile-time dependency injection logic as a +// Package wire provides compile-time dependency injection logic as a // Go library. -package goose +package wire import ( "bytes" @@ -53,8 +53,8 @@ func Generate(bctx *build.Context, wd string, pkg string) ([]byte, error) { } *conf.Build = *bctx n := len(conf.Build.BuildTags) - // TODO(light): Only apply gooseinject build tag on main package. - conf.Build.BuildTags = append(conf.Build.BuildTags[:n:n], "gooseinject") + // TODO(light): Only apply wireinject build tag on main package. + conf.Build.BuildTags = append(conf.Build.BuildTags[:n:n], "wireinject") conf.Import(pkg) prog, err := conf.Load() @@ -168,7 +168,7 @@ func (g *gen) frame() []byte { return nil } var buf bytes.Buffer - buf.WriteString("// Code generated by goose. DO NOT EDIT.\n\n//+build !gooseinject\n\npackage ") + buf.WriteString("// Code generated by gowire. DO NOT EDIT.\n\n//+build !wireinject\n\npackage ") buf.WriteString(g.prog.Package(g.currPackage).Pkg.Name()) buf.WriteString("\n\n") if len(g.imports) > 0 { diff --git a/internal/goose/goose_test.go b/internal/wire/wire_test.go similarity index 93% rename from internal/goose/goose_test.go rename to internal/wire/wire_test.go index 7d8d1a1..b66a50d 100644 --- a/internal/goose/goose_test.go +++ b/internal/wire/wire_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package goose +package wire import ( "bytes" @@ -33,7 +33,7 @@ import ( "unicode/utf8" ) -func TestGoose(t *testing.T) { +func TestWire(t *testing.T) { wd, err := os.Getwd() if err != nil { t.Fatal(err) @@ -45,7 +45,7 @@ func TestGoose(t *testing.T) { } // The marker function package source is needed to have the test cases // type check. loadTestCase places this file at the well-known import path. - gooseGo, err := ioutil.ReadFile(filepath.Join("..", "..", "goose.go")) + wireGo, err := ioutil.ReadFile(filepath.Join("..", "..", "wire.go")) if err != nil { t.Fatal(err) } @@ -55,7 +55,7 @@ func TestGoose(t *testing.T) { if !ent.IsDir() || strings.HasPrefix(name, ".") || strings.HasPrefix(name, "_") { continue } - test, err := loadTestCase(filepath.Join(testRoot, name), gooseGo) + test, err := loadTestCase(filepath.Join(testRoot, name), wireGo) if err != nil { t.Error(err) } @@ -71,19 +71,19 @@ func TestGoose(t *testing.T) { bctx := test.buildContext() gen, err := Generate(bctx, wd, test.pkg) if len(gen) > 0 { - defer t.Logf("goose_gen.go:\n%s", gen) + defer t.Logf("wire_gen.go:\n%s", gen) } if err != nil { if !test.wantError { - t.Fatalf("goose: %v", err) + t.Fatalf("wirego: %v", err) } return } if err == nil && test.wantError { - t.Fatal("goose succeeded; want error") + t.Fatal("wirego succeeded; want error") } - gopath, err := ioutil.TempDir("", "goose_test") + gopath, err := ioutil.TempDir("", "wire_test") if err != nil { t.Fatal(err) } @@ -92,7 +92,7 @@ func TestGoose(t *testing.T) { t.Fatal(err) } if len(gen) > 0 { - genPath := filepath.Join(gopath, "src", filepath.FromSlash(test.pkg), "goose_gen.go") + genPath := filepath.Join(gopath, "src", filepath.FromSlash(test.pkg), "wire_gen.go") if err := ioutil.WriteFile(genPath, gen, 0666); err != nil { t.Fatal(err) } @@ -135,16 +135,16 @@ func TestGoose(t *testing.T) { bctx := test.buildContext() gold, err := Generate(bctx, wd, test.pkg) if err != nil { - t.Fatal("goose:", err) + t.Fatal("wirego:", err) } goldstr := string(gold) for i := 0; i < runs-1; i++ { out, err := Generate(bctx, wd, test.pkg) if err != nil { - t.Fatal("goose (on subsequent run):", err) + t.Fatal("wirego (on subsequent run):", err) } if !bytes.Equal(gold, out) { - t.Fatalf("goose output differs when run repeatedly on same input:\n%s", diff(goldstr, string(out))) + t.Fatalf("wirego output differs when run repeatedly on same input:\n%s", diff(goldstr, string(out))) } } }) @@ -251,7 +251,7 @@ type testCase struct { // out.txt file containing the expected output, or the magic string "ERROR" // if this test should cause generation to fail // ... any Go files found recursively placed under GOPATH/src/... -func loadTestCase(root string, gooseGoSrc []byte) (*testCase, error) { +func loadTestCase(root string, wireGoSrc []byte) (*testCase, error) { name := filepath.Base(root) pkg, err := ioutil.ReadFile(filepath.Join(root, "pkg")) if err != nil { @@ -267,7 +267,7 @@ func loadTestCase(root string, gooseGoSrc []byte) (*testCase, error) { out = nil } goFiles := map[string][]byte{ - "github.com/google/go-cloud/goose/goose.go": gooseGoSrc, + "github.com/google/go-cloud/wire/wire.go": wireGoSrc, } err = filepath.Walk(root, func(src string, info os.FileInfo, err error) error { if err != nil { @@ -316,8 +316,8 @@ func (test *testCase) buildContext() *build.Context { } const ( - magicGOPATHUnix = "/goose_gopath" - magicGOPATHWindows = `C:\goose_gopath` + magicGOPATHUnix = "/wire_gopath" + magicGOPATHWindows = `C:\wire_gopath` ) func magicGOPATH() string { @@ -519,7 +519,7 @@ func diff(want, got string) string { } func runDiff(a, b []byte) ([]byte, error) { - fa, err := ioutil.TempFile("", "goose_test_diff") + fa, err := ioutil.TempFile("", "wire_test_diff") if err != nil { return nil, err } @@ -527,7 +527,7 @@ func runDiff(a, b []byte) ([]byte, error) { os.Remove(fa.Name()) fa.Close() }() - fb, err := ioutil.TempFile("", "goose_test_diff") + fb, err := ioutil.TempFile("", "wire_test_diff") if err != nil { return nil, err } diff --git a/goose.go b/wire.go similarity index 85% rename from goose.go rename to wire.go index 61ff8d8..22a8208 100644 --- a/goose.go +++ b/wire.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package goose contains directives for goose code generation. -package goose +// Package wire contains directives for Wire code generation. +package wire // ProviderSet is a marker type that collects a group of providers. type ProviderSet struct{} @@ -33,10 +33,10 @@ func NewSet(...interface{}) ProviderSet { // Example: // // func injector(ctx context.Context) (*sql.DB, error) { -// panic(goose.Build(otherpkg.FooSet, myProviderFunc)) +// panic(wire.Build(otherpkg.FooSet, myProviderFunc)) // } func Build(...interface{}) string { - return "implementation not generated, run goose" + return "implementation not generated, run gowire" } // A Binding maps an interface to a concrete type. @@ -48,7 +48,7 @@ type Binding struct{} // // Example: // -// var MySet = goose.NewSet(goose.Bind(new(MyInterface), new(MyStruct))) +// var MySet = wire.NewSet(wire.Bind(new(MyInterface), new(MyStruct))) func Bind(iface, to interface{}) Binding { return Binding{} } @@ -60,7 +60,7 @@ type ProvidedValue struct{} // // Example: // -// var MySet = goose.NewSet(goose.Value([]string(nil))) +// var MySet = wire.NewSet(wire.Value([]string(nil))) func Value(interface{}) ProvidedValue { return ProvidedValue{} }