wire: Add wire.InterfaceValue, required instead of wire.Value if the value is an interface value (google/go-cloud#322)
* Add wire.InterfaceValue, required instead of wire.Value if the value is an interface value. * Update guestbook sample to use InterfaceValue where appropriate. * Remove unnecessary ok := true * Addressing comments from code review.
This commit is contained in:
committed by
Ross Light
parent
eedae3d8d0
commit
cd32a686b1
26
internal/wire/testdata/InterfaceValue/foo/foo.go
vendored
Normal file
26
internal/wire/testdata/InterfaceValue/foo/foo.go
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright 2018 The Go Cloud Authors
|
||||
//
|
||||
// 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.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func main() {
|
||||
r := injectedReader()
|
||||
buf, _ := ioutil.ReadAll(r)
|
||||
fmt.Println(string(buf))
|
||||
}
|
||||
29
internal/wire/testdata/InterfaceValue/foo/wire.go
vendored
Normal file
29
internal/wire/testdata/InterfaceValue/foo/wire.go
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright 2018 The Go Cloud Authors
|
||||
//
|
||||
// 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 (
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/google/go-cloud/wire"
|
||||
)
|
||||
|
||||
func injectedReader() io.Reader {
|
||||
wire.Build(wire.InterfaceValue(new(io.Reader), strings.NewReader("hello world")))
|
||||
return nil
|
||||
}
|
||||
1
internal/wire/testdata/InterfaceValue/pkg
vendored
Normal file
1
internal/wire/testdata/InterfaceValue/pkg
vendored
Normal file
@@ -0,0 +1 @@
|
||||
foo
|
||||
1
internal/wire/testdata/InterfaceValue/want/program_out.txt
vendored
Normal file
1
internal/wire/testdata/InterfaceValue/want/program_out.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
hello world
|
||||
22
internal/wire/testdata/InterfaceValue/want/wire_gen.go
vendored
Normal file
22
internal/wire/testdata/InterfaceValue/want/wire_gen.go
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
// Code generated by Wire. DO NOT EDIT.
|
||||
|
||||
//go:generate wire
|
||||
//+build !wireinject
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
io "io"
|
||||
strings "strings"
|
||||
)
|
||||
|
||||
// Injectors from wire.go:
|
||||
|
||||
func injectedReader() io.Reader {
|
||||
reader := _wireReaderValue
|
||||
return reader
|
||||
}
|
||||
|
||||
var (
|
||||
_wireReaderValue = strings.NewReader("hello world")
|
||||
)
|
||||
21
internal/wire/testdata/InterfaceValueInvalidArg0/foo/foo.go
vendored
Normal file
21
internal/wire/testdata/InterfaceValueInvalidArg0/foo/foo.go
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright 2018 The Go Cloud Authors
|
||||
//
|
||||
// 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.
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println(injectedMessage())
|
||||
}
|
||||
26
internal/wire/testdata/InterfaceValueInvalidArg0/foo/wire.go
vendored
Normal file
26
internal/wire/testdata/InterfaceValueInvalidArg0/foo/wire.go
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright 2018 The Go Cloud Authors
|
||||
//
|
||||
// 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 {
|
||||
wire.Build(wire.InterfaceValue("foo", "bar"))
|
||||
return ""
|
||||
}
|
||||
1
internal/wire/testdata/InterfaceValueInvalidArg0/pkg
vendored
Normal file
1
internal/wire/testdata/InterfaceValueInvalidArg0/pkg
vendored
Normal file
@@ -0,0 +1 @@
|
||||
foo
|
||||
1
internal/wire/testdata/InterfaceValueInvalidArg0/want/wire_errs.txt
vendored
Normal file
1
internal/wire/testdata/InterfaceValueInvalidArg0/want/wire_errs.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
first argument to InterfaceValue must be a pointer to an interface type; found string
|
||||
21
internal/wire/testdata/InterfaceValueNotEnoughArgs/foo/foo.go
vendored
Normal file
21
internal/wire/testdata/InterfaceValueNotEnoughArgs/foo/foo.go
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright 2018 The Go Cloud Authors
|
||||
//
|
||||
// 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.
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println(injectedMessage())
|
||||
}
|
||||
26
internal/wire/testdata/InterfaceValueNotEnoughArgs/foo/wire.go
vendored
Normal file
26
internal/wire/testdata/InterfaceValueNotEnoughArgs/foo/wire.go
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright 2018 The Go Cloud Authors
|
||||
//
|
||||
// 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 {
|
||||
wire.Build(wire.InterfaceValue("foo"))
|
||||
return ""
|
||||
}
|
||||
1
internal/wire/testdata/InterfaceValueNotEnoughArgs/pkg
vendored
Normal file
1
internal/wire/testdata/InterfaceValueNotEnoughArgs/pkg
vendored
Normal file
@@ -0,0 +1 @@
|
||||
foo
|
||||
1
internal/wire/testdata/InterfaceValueNotEnoughArgs/want/wire_errs.txt
vendored
Normal file
1
internal/wire/testdata/InterfaceValueNotEnoughArgs/want/wire_errs.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
too few arguments in call to wire.InterfaceValue
|
||||
27
internal/wire/testdata/ValueIsInterfaceValue/foo/foo.go
vendored
Normal file
27
internal/wire/testdata/ValueIsInterfaceValue/foo/foo.go
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright 2018 The Go Cloud Authors
|
||||
//
|
||||
// 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.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
r := injectedReader(strings.NewReader("hello world"))
|
||||
buf, _ := ioutil.ReadAll(r)
|
||||
fmt.Println(string(buf))
|
||||
}
|
||||
29
internal/wire/testdata/ValueIsInterfaceValue/foo/wire.go
vendored
Normal file
29
internal/wire/testdata/ValueIsInterfaceValue/foo/wire.go
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright 2018 The Go Cloud Authors
|
||||
//
|
||||
// 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 (
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/google/go-cloud/wire"
|
||||
)
|
||||
|
||||
func injectedReader(r *strings.Reader) io.Reader {
|
||||
wire.Build(wire.Value(io.Reader(r)))
|
||||
return nil
|
||||
}
|
||||
1
internal/wire/testdata/ValueIsInterfaceValue/pkg
vendored
Normal file
1
internal/wire/testdata/ValueIsInterfaceValue/pkg
vendored
Normal file
@@ -0,0 +1 @@
|
||||
foo
|
||||
1
internal/wire/testdata/ValueIsInterfaceValue/want/wire_errs.txt
vendored
Normal file
1
internal/wire/testdata/ValueIsInterfaceValue/want/wire_errs.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
argument to Value may not be an interface value (found io.Reader); use InterfaceValue instead
|
||||
Reference in New Issue
Block a user