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
This commit is contained in:
Ross Light
2018-05-31 15:34:15 -07:00
parent 3e60790b34
commit 6345348d86
131 changed files with 285 additions and 293 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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!")))
}

View File

@@ -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))
}

View File

@@ -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)))
}

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package goose
package wire
import (
"fmt"

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package goose
package wire
import (
"fmt"

View File

@@ -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"
}

View File

@@ -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)

View File

@@ -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))
}

View File

@@ -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))
}

View File

@@ -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))
}

View File

@@ -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))
}

View File

@@ -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!"

View File

@@ -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))
}

View File

@@ -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)

View File

@@ -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))
}

View File

@@ -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)))

View File

@@ -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))
}

View File

@@ -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)

View File

@@ -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))
}

View File

@@ -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)

View File

@@ -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))
}

View File

@@ -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)))

View File

@@ -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))
}

View File

@@ -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))))
}

View File

@@ -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))
}

View File

@@ -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() {

View File

@@ -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))
}

View File

@@ -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!")))
}

View File

@@ -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))
}

View File

@@ -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))
}

View File

@@ -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))
}

View File

@@ -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)

View File

@@ -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))
}

View File

@@ -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)

View File

@@ -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))
}

View File

@@ -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)

View File

@@ -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))
}

View File

@@ -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)

View File

@@ -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))
}

Some files were not shown because too many files have changed in this diff Show More