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:
76
README.md
76
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
|
[Dagger][]. It works by using Go code to specify dependencies, then
|
||||||
generating code to create those structures, mimicking the code that a user
|
generating code to create those structures, mimicking the code that a user
|
||||||
might have hand-written.
|
might have hand-written.
|
||||||
@@ -12,7 +12,7 @@ might have hand-written.
|
|||||||
|
|
||||||
### Defining Providers
|
### 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.
|
produce a value. These functions are ordinary Go code.
|
||||||
|
|
||||||
```go
|
```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
|
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
|
```go
|
||||||
package foobarbaz
|
package foobarbaz
|
||||||
|
|
||||||
import (
|
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.
|
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
|
### Injectors
|
||||||
|
|
||||||
An application wires up these providers with an **injector**: a function that
|
An application wires up these providers with an **injector**: a function that
|
||||||
calls providers in dependency order. With goose, you write the injector's
|
calls providers in dependency order. With Wire, you write the injector's
|
||||||
signature, then goose generates the function's body.
|
signature, then Wire generates the function's body.
|
||||||
|
|
||||||
An injector is declared by writing a function declaration whose body is a call
|
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
|
above providers were defined in a package called `example.com/foobarbaz`. The
|
||||||
following would declare an injector to obtain a `Baz`:
|
following would declare an injector to obtain a `Baz`:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
// +build gooseinject
|
// +build wireinject
|
||||||
|
|
||||||
// ^ build tag makes sure the stub is not built in the final build
|
// ^ build tag makes sure the stub is not built in the final build
|
||||||
|
|
||||||
@@ -116,30 +116,30 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
"example.com/foobarbaz"
|
"example.com/foobarbaz"
|
||||||
)
|
)
|
||||||
|
|
||||||
func initializeApp(ctx context.Context) (foobarbaz.Baz, error) {
|
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
|
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
|
providers) and can return errors. Arguments to `wire.Build` are the same as
|
||||||
`goose.NewSet`: they form a provider set. This is the provider set that gets
|
`wire.NewSet`: they form a provider set. This is the provider set that gets
|
||||||
used during code generation for that injector.
|
used during code generation for that injector.
|
||||||
|
|
||||||
Any non-injector declarations found in a file with injectors will be copied into
|
Any non-injector declarations found in a file with injectors will be copied into
|
||||||
the generated file.
|
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`]:
|
use [`go generate`]:
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -149,13 +149,13 @@ go generate
|
|||||||
(Adding the line to the injection declaration file will be silently ignored by
|
(Adding the line to the injection declaration file will be silently ignored by
|
||||||
`go generate`.)
|
`go generate`.)
|
||||||
|
|
||||||
goose will produce an implementation of the injector in a file called
|
Wire will produce an implementation of the injector in a file called
|
||||||
`goose_gen.go` that looks something like this:
|
`wire_gen.go` that looks something like this:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
// Code generated by goose. DO NOT EDIT.
|
// Code generated by gowire. DO NOT EDIT.
|
||||||
|
|
||||||
//+build !gooseinject
|
//+build !wireinject
|
||||||
|
|
||||||
package main
|
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
|
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
|
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 goose.
|
written code is just normal Go code, and can be used without Wire.
|
||||||
|
|
||||||
[`go generate`]: https://blog.golang.org/generate
|
[`go generate`]: https://blog.golang.org/generate
|
||||||
|
|
||||||
## Best Practices
|
## Best Practices
|
||||||
|
|
||||||
goose is still not mature yet, but guidance that applies to Dagger generally
|
Wire 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
|
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)
|
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):
|
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
|
> - The [provider sets] should each include the no-reasonable-alternative
|
||||||
> [provider sets] that require the [...] bindings each provides.
|
> [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
|
would use a binding annotation. For example, if you need to pass a string
|
||||||
through the dependency graph, you would create a wrapping type:
|
through the dependency graph, you would create a wrapping type:
|
||||||
|
|
||||||
@@ -222,7 +222,7 @@ type MySQLConnectionString string
|
|||||||
### Binding Interfaces
|
### Binding Interfaces
|
||||||
|
|
||||||
Frequently, dependency injection is used to bind concrete implementations for an
|
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.
|
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
|
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
|
concrete types][]. Instead, you can declare an interface binding in a
|
||||||
@@ -245,12 +245,12 @@ func ProvideBar() *Bar {
|
|||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
var BarFooer = goose.NewSet(
|
var BarFooer = wire.NewSet(
|
||||||
ProvideBar,
|
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 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
|
interface binding does not necessarily need to have a provider in the same set
|
||||||
that provides the concrete type.
|
that provides the concrete type.
|
||||||
@@ -282,7 +282,7 @@ type FooBar struct {
|
|||||||
Bar Bar
|
Bar Bar
|
||||||
}
|
}
|
||||||
|
|
||||||
var Set = goose.NewSet(
|
var Set = wire.NewSet(
|
||||||
ProvideFoo,
|
ProvideFoo,
|
||||||
ProvideBar,
|
ProvideBar,
|
||||||
FooBar{})
|
FooBar{})
|
||||||
@@ -314,7 +314,7 @@ add a value expression to a provider set.
|
|||||||
type Foo int
|
type Foo int
|
||||||
|
|
||||||
func injectFoo() Foo {
|
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
|
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.
|
an error if the expression calls any functions.
|
||||||
|
|
||||||
### Cleanup 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
|
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()`.
|
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
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// 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.
|
// See README.md for an overview.
|
||||||
package main
|
package main
|
||||||
@@ -30,7 +30,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/google/go-cloud/goose/internal/goose"
|
"github.com/google/go-cloud/wire/internal/wire"
|
||||||
"golang.org/x/tools/go/types/typeutil"
|
"golang.org/x/tools/go/types/typeutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -48,17 +48,17 @@ func main() {
|
|||||||
case len(os.Args) == 3 && os.Args[1] == "gen":
|
case len(os.Args) == 3 && os.Args[1] == "gen":
|
||||||
err = generate(os.Args[2])
|
err = generate(os.Args[2])
|
||||||
default:
|
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)
|
os.Exit(64)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, "goose:", err)
|
fmt.Fprintln(os.Stderr, "gowire:", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate runs the gen subcommand. Given a package, gen will create
|
// 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 {
|
func generate(pkg string) error {
|
||||||
wd, err := os.Getwd()
|
wd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -68,16 +68,16 @@ func generate(pkg string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
out, err := goose.Generate(&build.Default, wd, pkg)
|
out, err := wire.Generate(&build.Default, wd, pkg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(out) == 0 {
|
if len(out) == 0 {
|
||||||
// No Goose directives, don't write anything.
|
// No Wire directives, don't write anything.
|
||||||
fmt.Fprintln(os.Stderr, "goose: no injector found for", pkg)
|
fmt.Fprintln(os.Stderr, "gowire: no injector found for", pkg)
|
||||||
return nil
|
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 {
|
if err := ioutil.WriteFile(p, out, 0666); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -94,11 +94,11 @@ func show(pkgs ...string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
info, err := goose.Load(&build.Default, wd, pkgs)
|
info, err := wire.Load(&build.Default, wd, pkgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
keys := make([]goose.ProviderSetID, 0, len(info.Sets))
|
keys := make([]wire.ProviderSetID, 0, len(info.Sets))
|
||||||
for k := range info.Sets {
|
for k := range info.Sets {
|
||||||
keys = append(keys, k)
|
keys = append(keys, k)
|
||||||
}
|
}
|
||||||
@@ -130,11 +130,11 @@ func show(pkgs ...string) error {
|
|||||||
out := make(map[string]token.Pos, outGroups[i].outputs.Len())
|
out := make(map[string]token.Pos, outGroups[i].outputs.Len())
|
||||||
outGroups[i].outputs.Iterate(func(t types.Type, v interface{}) {
|
outGroups[i].outputs.Iterate(func(t types.Type, v interface{}) {
|
||||||
switch v := v.(type) {
|
switch v := v.(type) {
|
||||||
case *goose.Provider:
|
case *wire.Provider:
|
||||||
out[types.TypeString(t, nil)] = v.Pos
|
out[types.TypeString(t, nil)] = v.Pos
|
||||||
case *goose.Value:
|
case *wire.Value:
|
||||||
out[types.TypeString(t, nil)] = v.Pos
|
out[types.TypeString(t, nil)] = v.Pos
|
||||||
case *goose.IfaceBinding:
|
case *wire.IfaceBinding:
|
||||||
out[types.TypeString(t, nil)] = v.Pos
|
out[types.TypeString(t, nil)] = v.Pos
|
||||||
default:
|
default:
|
||||||
panic("unreachable")
|
panic("unreachable")
|
||||||
@@ -152,19 +152,19 @@ func show(pkgs ...string) error {
|
|||||||
type outGroup struct {
|
type outGroup struct {
|
||||||
name string
|
name string
|
||||||
inputs *typeutil.Map // values are not important
|
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
|
// gather flattens a provider set into outputs grouped by the inputs
|
||||||
// required to create them. As it flattens the provider set, it records
|
// required to create them. As it flattens the provider set, it records
|
||||||
// the visited named provider sets as imports.
|
// 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()
|
hash := typeutil.MakeHasher()
|
||||||
// Map types to providers and bindings.
|
// Map types to providers and bindings.
|
||||||
pm := new(typeutil.Map)
|
pm := new(typeutil.Map)
|
||||||
pm.SetHasher(hash)
|
pm.SetHasher(hash)
|
||||||
next := []*goose.ProviderSet{info.Sets[key]}
|
next := []*wire.ProviderSet{info.Sets[key]}
|
||||||
visited := make(map[*goose.ProviderSet]struct{})
|
visited := make(map[*wire.ProviderSet]struct{})
|
||||||
imports = make(map[string]struct{})
|
imports = make(map[string]struct{})
|
||||||
for len(next) > 0 {
|
for len(next) > 0 {
|
||||||
curr := next[len(next)-1]
|
curr := next[len(next)-1]
|
||||||
@@ -214,7 +214,7 @@ func gather(info *goose.Info, key goose.ProviderSetID) (_ []outGroup, imports ma
|
|||||||
case nil:
|
case nil:
|
||||||
// This is an input.
|
// This is an input.
|
||||||
inputVisited.Set(curr, -1)
|
inputVisited.Set(curr, -1)
|
||||||
case *goose.Provider:
|
case *wire.Provider:
|
||||||
// Try to see if any args haven't been visited.
|
// Try to see if any args haven't been visited.
|
||||||
allPresent := true
|
allPresent := true
|
||||||
for _, arg := range p.Args {
|
for _, arg := range p.Args {
|
||||||
@@ -258,7 +258,7 @@ func gather(info *goose.Info, key goose.ProviderSetID) (_ []outGroup, imports ma
|
|||||||
inputs: in,
|
inputs: in,
|
||||||
outputs: out,
|
outputs: out,
|
||||||
})
|
})
|
||||||
case *goose.Value:
|
case *wire.Value:
|
||||||
for i := range groups {
|
for i := range groups {
|
||||||
if groups[i].inputs.Len() == 0 {
|
if groups[i].inputs.Len() == 0 {
|
||||||
groups[i].outputs.Set(p.Out, p)
|
groups[i].outputs.Set(p.Out, p)
|
||||||
@@ -276,7 +276,7 @@ func gather(info *goose.Info, key goose.ProviderSetID) (_ []outGroup, imports ma
|
|||||||
inputs: in,
|
inputs: in,
|
||||||
outputs: out,
|
outputs: out,
|
||||||
})
|
})
|
||||||
case *goose.IfaceBinding:
|
case *wire.IfaceBinding:
|
||||||
i, ok := inputVisited.At(p.Provided).(int)
|
i, ok := inputVisited.At(p.Provided).(int)
|
||||||
if !ok {
|
if !ok {
|
||||||
stk = append(stk, curr, p.Provided)
|
stk = append(stk, curr, p.Provided)
|
||||||
@@ -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!")))
|
|
||||||
}
|
|
||||||
25
internal/goose/testdata/ValueChain/foo/goose.go
vendored
25
internal/goose/testdata/ValueChain/foo/goose.go
vendored
@@ -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))
|
|
||||||
}
|
|
||||||
25
internal/goose/testdata/VarValue/foo/goose.go
vendored
25
internal/goose/testdata/VarValue/foo/goose.go
vendored
@@ -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)))
|
|
||||||
}
|
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package goose
|
package wire
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package goose
|
package wire
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package goose
|
package wire
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@@ -31,7 +31,7 @@ import (
|
|||||||
// A ProviderSet describes a set of providers. The zero value is an empty
|
// A ProviderSet describes a set of providers. The zero value is an empty
|
||||||
// ProviderSet.
|
// ProviderSet.
|
||||||
type ProviderSet struct {
|
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.
|
// created the set.
|
||||||
Pos token.Pos
|
Pos token.Pos
|
||||||
// PkgPath is the import path of the package that declared this set.
|
// 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 is the type this value produces.
|
||||||
Out types.Type
|
Out types.Type
|
||||||
|
|
||||||
// expr is the expression passed to goose.Value.
|
// expr is the expression passed to wire.Value.
|
||||||
expr ast.Expr
|
expr ast.Expr
|
||||||
|
|
||||||
// info is the type info for the expression.
|
// info is the type info for the expression.
|
||||||
@@ -177,7 +177,7 @@ func (id ProviderSetID) String() string {
|
|||||||
return strconv.Quote(id.ImportPath) + "." + id.VarName
|
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 {
|
type objectCache struct {
|
||||||
prog *loader.Program
|
prog *loader.Program
|
||||||
objects map[objRef]interface{} // *Provider, *ProviderSet, *IfaceBinding, or *Value
|
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,
|
// *Provider, a structProviderPair, an *IfaceBinding, a *ProviderSet,
|
||||||
// or a *Value.
|
// or a *Value.
|
||||||
func (oc *objectCache) get(obj types.Object) (interface{}, error) {
|
func (oc *objectCache) get(obj types.Object) (interface{}, error) {
|
||||||
@@ -256,7 +256,7 @@ func (oc *objectCache) varDecl(obj *types.Var) *ast.ValueSpec {
|
|||||||
return nil
|
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
|
// return a *Provider, a structProviderPair, an *IfaceBinding, a
|
||||||
// *ProviderSet, or a *Value.
|
// *ProviderSet, or a *Value.
|
||||||
func (oc *objectCache) processExpr(pkg *loader.PackageInfo, expr ast.Expr) (interface{}, error) {
|
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 {
|
if call, ok := expr.(*ast.CallExpr); ok {
|
||||||
fnObj := qualifiedIdentObject(&pkg.Info, call.Fun)
|
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)
|
return nil, fmt.Errorf("%v: unknown pattern", exprPos)
|
||||||
}
|
}
|
||||||
switch fnObj.Name() {
|
switch fnObj.Name() {
|
||||||
@@ -316,7 +316,7 @@ type structProviderPair struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (oc *objectCache) processNewSet(pkg *loader.PackageInfo, call *ast.CallExpr) (*ProviderSet, error) {
|
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{
|
pset := &ProviderSet{
|
||||||
Pos: call.Pos(),
|
Pos: call.Pos(),
|
||||||
@@ -488,9 +488,9 @@ func processStructProvider(fset *token.FileSet, typeName *types.TypeName) (*Prov
|
|||||||
return provider, nil
|
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) {
|
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 {
|
if len(call.Args) != 2 {
|
||||||
return nil, fmt.Errorf("%v: call to Bind takes exactly two arguments", fset.Position(call.Pos()))
|
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
|
}, 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) {
|
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 {
|
if len(call.Args) != 1 {
|
||||||
return nil, fmt.Errorf("%v: call to Value takes exactly one argument", fset.Position(call.Pos()))
|
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
|
// 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.
|
// the function is not an injector template.
|
||||||
func isInjector(info *types.Info, fn *ast.FuncDecl) *ast.CallExpr {
|
func isInjector(info *types.Info, fn *ast.FuncDecl) *ast.CallExpr {
|
||||||
if fn.Body == nil {
|
if fn.Body == nil {
|
||||||
@@ -604,17 +604,17 @@ func isInjector(info *types.Info, fn *ast.FuncDecl) *ast.CallExpr {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
buildObj := qualifiedIdentObject(info, buildCall.Fun)
|
buildObj := qualifiedIdentObject(info, buildCall.Fun)
|
||||||
if !isGooseImport(buildObj.Pkg().Path()) || buildObj.Name() != "Build" {
|
if !isWireImport(buildObj.Pkg().Path()) || buildObj.Name() != "Build" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return buildCall
|
return buildCall
|
||||||
}
|
}
|
||||||
|
|
||||||
func isGooseImport(path string) bool {
|
func isWireImport(path string) bool {
|
||||||
// TODO(light): This is depending on details of the current loader.
|
// TODO(light): This is depending on details of the current loader.
|
||||||
const vendorPart = "vendor/"
|
const vendorPart = "vendor/"
|
||||||
if i := strings.LastIndex(path, vendorPart); i != -1 && (i == 0 || path[i-1] == '/') {
|
if i := strings.LastIndex(path, vendorPart); i != -1 && (i == 0 || path[i-1] == '/') {
|
||||||
path = path[i+len(vendorPart):]
|
path = path[i+len(vendorPart):]
|
||||||
}
|
}
|
||||||
return path == "github.com/google/go-cloud/goose"
|
return path == "github.com/google/go-cloud/wire"
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -27,7 +27,7 @@ func main() {
|
|||||||
type Foo int
|
type Foo int
|
||||||
type FooBar int
|
type FooBar int
|
||||||
|
|
||||||
var Set = goose.NewSet(
|
var Set = wire.NewSet(
|
||||||
provideFoo,
|
provideFoo,
|
||||||
provideFooBar)
|
provideFooBar)
|
||||||
|
|
||||||
@@ -12,14 +12,14 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//+build gooseinject
|
//+build wireinject
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func injectFooBar() FooBar {
|
func injectFooBar() FooBar {
|
||||||
panic(goose.Build(Set))
|
panic(wire.Build(Set))
|
||||||
}
|
}
|
||||||
@@ -12,14 +12,14 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//+build gooseinject
|
//+build wireinject
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func injectBar() (*Bar, func()) {
|
func injectBar() (*Bar, func()) {
|
||||||
panic(goose.Build(provideFoo, provideBar))
|
panic(wire.Build(provideFoo, provideBar))
|
||||||
}
|
}
|
||||||
@@ -12,17 +12,17 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//+build gooseinject
|
//+build wireinject
|
||||||
|
|
||||||
// All of the declarations are in one file.
|
// 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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -35,5 +35,5 @@ func provideMessage() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func injectedMessage() string {
|
func injectedMessage() string {
|
||||||
panic(goose.Build(provideMessage))
|
panic(wire.Build(provideMessage))
|
||||||
}
|
}
|
||||||
@@ -12,14 +12,14 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//+build gooseinject
|
//+build wireinject
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func injectedMessage() string {
|
func injectedMessage() string {
|
||||||
panic(goose.Build(myFakeSet))
|
panic(wire.Build(myFakeSet))
|
||||||
}
|
}
|
||||||
@@ -14,8 +14,8 @@
|
|||||||
|
|
||||||
package bar
|
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!"
|
var PublicMsg = "Hello, World!"
|
||||||
@@ -12,15 +12,15 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//+build gooseinject
|
//+build wireinject
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bar"
|
"bar"
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func injectedMessage() string {
|
func injectedMessage() string {
|
||||||
panic(goose.Build(bar.Value))
|
panic(wire.Build(bar.Value))
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,7 @@ package bar
|
|||||||
import (
|
import (
|
||||||
"os"
|
"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)
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//+build gooseinject
|
//+build wireinject
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
@@ -20,9 +20,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"bar"
|
"bar"
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func injectedFile() *os.File {
|
func injectedFile() *os.File {
|
||||||
panic(goose.Build(bar.Value))
|
panic(wire.Build(bar.Value))
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"foo"
|
"foo"
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -37,6 +37,6 @@ func provideBar() *Bar {
|
|||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
var Set = goose.NewSet(
|
var Set = wire.NewSet(
|
||||||
provideBar,
|
provideBar,
|
||||||
goose.Bind((*foo.Fooer)(nil), (*Bar)(nil)))
|
wire.Bind((*foo.Fooer)(nil), (*Bar)(nil)))
|
||||||
@@ -12,15 +12,15 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//+build gooseinject
|
//+build wireinject
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
"foo"
|
"foo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func injectFooer() foo.Fooer {
|
func injectFooer() foo.Fooer {
|
||||||
panic(goose.Build(Set))
|
panic(wire.Build(Set))
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -28,7 +28,7 @@ type Foo int
|
|||||||
type Bar int
|
type Bar int
|
||||||
type FooBar int
|
type FooBar int
|
||||||
|
|
||||||
var Set = goose.NewSet(
|
var Set = wire.NewSet(
|
||||||
provideBar,
|
provideBar,
|
||||||
provideFooBar)
|
provideFooBar)
|
||||||
|
|
||||||
@@ -12,14 +12,14 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//+build gooseinject
|
//+build wireinject
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func injectFooBar(foo Foo) FooBar {
|
func injectFooBar(foo Foo) FooBar {
|
||||||
panic(goose.Build(Set))
|
panic(wire.Build(Set))
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -30,7 +30,7 @@ func main() {
|
|||||||
type Foo int
|
type Foo int
|
||||||
type Bar int
|
type Bar int
|
||||||
|
|
||||||
var Set = goose.NewSet(
|
var Set = wire.NewSet(
|
||||||
provideFoo,
|
provideFoo,
|
||||||
provideBar)
|
provideBar)
|
||||||
|
|
||||||
@@ -12,14 +12,14 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//+build gooseinject
|
//+build wireinject
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func injectBar(foo Foo) Bar {
|
func injectBar(foo Foo) Bar {
|
||||||
panic(goose.Build(Set))
|
panic(wire.Build(Set))
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -40,6 +40,6 @@ func provideBar() *Bar {
|
|||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
var Set = goose.NewSet(
|
var Set = wire.NewSet(
|
||||||
provideBar,
|
provideBar,
|
||||||
goose.Bind((*Fooer)(nil), (*Bar)(nil)))
|
wire.Bind((*Fooer)(nil), (*Bar)(nil)))
|
||||||
@@ -12,14 +12,14 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//+build gooseinject
|
//+build wireinject
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func injectFooer() Fooer {
|
func injectFooer() Fooer {
|
||||||
panic(goose.Build(Set))
|
panic(wire.Build(Set))
|
||||||
}
|
}
|
||||||
@@ -12,17 +12,17 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//+build gooseinject
|
//+build wireinject
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func injectFooBar() FooBar {
|
func injectFooBar() FooBar {
|
||||||
panic(goose.Build(
|
panic(wire.Build(
|
||||||
provideBar,
|
provideBar,
|
||||||
provideFooBar,
|
provideFooBar,
|
||||||
goose.Bind((*Fooer)(nil), (*Bar)(nil))))
|
wire.Bind((*Fooer)(nil), (*Bar)(nil))))
|
||||||
}
|
}
|
||||||
@@ -12,16 +12,16 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//+build gooseinject
|
//+build wireinject
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
stdcontext "context"
|
stdcontext "context"
|
||||||
|
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func inject(context stdcontext.Context, err struct{}) (context, error) {
|
func inject(context stdcontext.Context, err struct{}) (context, error) {
|
||||||
panic(goose.Build(provide))
|
panic(wire.Build(provide))
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//+build gooseinject
|
//+build wireinject
|
||||||
|
|
||||||
// This file is specifically designed to cause issues with copying the
|
// This file is specifically designed to cause issues with copying the
|
||||||
// AST, particularly with the identifier "context".
|
// AST, particularly with the identifier "context".
|
||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
type context struct{}
|
type context struct{}
|
||||||
@@ -51,7 +51,7 @@ func Provide(context2 stdcontext.Context) (context, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func inject(context stdcontext.Context, err struct{}) (context, error) {
|
func inject(context stdcontext.Context, err struct{}) (context, error) {
|
||||||
panic(goose.Build(Provide))
|
panic(wire.Build(Provide))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (context) Provide() {
|
func (context) Provide() {
|
||||||
@@ -12,14 +12,14 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//+build gooseinject
|
//+build wireinject
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func injectedMessage() string {
|
func injectedMessage() string {
|
||||||
panic(goose.Build(provideMessage))
|
panic(wire.Build(provideMessage))
|
||||||
}
|
}
|
||||||
25
internal/wire/testdata/NiladicValue/foo/wire.go
vendored
Normal file
25
internal/wire/testdata/NiladicValue/foo/wire.go
vendored
Normal 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!")))
|
||||||
|
}
|
||||||
@@ -12,14 +12,14 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//+build gooseinject
|
//+build wireinject
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func injectFooer() Fooer {
|
func injectFooer() Fooer {
|
||||||
panic(goose.Build(provideBar))
|
panic(wire.Build(provideBar))
|
||||||
}
|
}
|
||||||
@@ -12,19 +12,19 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//+build gooseinject
|
//+build wireinject
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
stdcontext "context"
|
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
|
// The notable characteristic of this test is that there are no
|
||||||
// parameter names on the inject stub.
|
// parameter names on the inject stub.
|
||||||
|
|
||||||
func inject(stdcontext.Context, struct{}) (context, error) {
|
func inject(stdcontext.Context, struct{}) (context, error) {
|
||||||
panic(goose.Build(provide))
|
panic(wire.Build(provide))
|
||||||
}
|
}
|
||||||
@@ -12,14 +12,14 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//+build gooseinject
|
//+build wireinject
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func injectBaz() (Baz, func(), error) {
|
func injectBaz() (Baz, func(), error) {
|
||||||
panic(goose.Build(provideFoo, provideBar, provideBaz))
|
panic(wire.Build(provideFoo, provideBar, provideBaz))
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"bar"
|
"bar"
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -28,7 +28,7 @@ func main() {
|
|||||||
type Foo int
|
type Foo int
|
||||||
type FooBar int
|
type FooBar int
|
||||||
|
|
||||||
var Set = goose.NewSet(
|
var Set = wire.NewSet(
|
||||||
provideFoo,
|
provideFoo,
|
||||||
bar.ProvideBar,
|
bar.ProvideBar,
|
||||||
provideFooBar)
|
provideFooBar)
|
||||||
@@ -12,14 +12,14 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//+build gooseinject
|
//+build wireinject
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func injectFooBar() FooBar {
|
func injectFooBar() FooBar {
|
||||||
panic(goose.Build(Set))
|
panic(wire.Build(Set))
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -38,4 +38,4 @@ func provideFoo() (Foo, error) {
|
|||||||
return 42, errors.New("there is no Foo")
|
return 42, errors.New("there is no Foo")
|
||||||
}
|
}
|
||||||
|
|
||||||
var Set = goose.NewSet(provideFoo)
|
var Set = wire.NewSet(provideFoo)
|
||||||
@@ -12,14 +12,14 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//+build gooseinject
|
//+build wireinject
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func injectFoo() (Foo, error) {
|
func injectFoo() (Foo, error) {
|
||||||
panic(goose.Build(Set))
|
panic(wire.Build(Set))
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -41,7 +41,7 @@ func provideBar() Bar {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
var Set = goose.NewSet(
|
var Set = wire.NewSet(
|
||||||
FooBar{},
|
FooBar{},
|
||||||
provideFoo,
|
provideFoo,
|
||||||
provideBar)
|
provideBar)
|
||||||
@@ -12,14 +12,14 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//+build gooseinject
|
//+build wireinject
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func injectFooBar() FooBar {
|
func injectFooBar() FooBar {
|
||||||
panic(goose.Build(Set))
|
panic(wire.Build(Set))
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -41,7 +41,7 @@ func provideBar() Bar {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
var Set = goose.NewSet(
|
var Set = wire.NewSet(
|
||||||
FooBar{},
|
FooBar{},
|
||||||
provideFoo,
|
provideFoo,
|
||||||
provideBar)
|
provideBar)
|
||||||
@@ -12,14 +12,14 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//+build gooseinject
|
//+build wireinject
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/go-cloud/goose"
|
"github.com/google/go-cloud/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func injectFooBar() *FooBar {
|
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
Reference in New Issue
Block a user