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

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

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