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:
Robert van Gent
2018-08-14 14:55:28 -07:00
committed by Ross Light
parent eedae3d8d0
commit cd32a686b1
20 changed files with 296 additions and 3 deletions

14
wire.go
View File

@@ -20,8 +20,8 @@ type ProviderSet struct{}
// NewSet creates a new provider set that includes the providers in
// its arguments. Each argument is either an exported function value,
// an exported struct (zero) value, a provider set, a call to Bind, or
// a call to Value.
// an exported struct (zero) value, a provider set, a call to Bind, a
// a call to Value, or a call to InterfaceValue.
func NewSet(...interface{}) ProviderSet {
return ProviderSet{}
}
@@ -72,6 +72,7 @@ func Bind(iface, to interface{}) Binding {
type ProvidedValue struct{}
// Value binds an expression to provide the type of the expression.
// The expression may not be an interface value; use InterfaceValue for that.
//
// Example:
//
@@ -79,3 +80,12 @@ type ProvidedValue struct{}
func Value(interface{}) ProvidedValue {
return ProvidedValue{}
}
// InterfaceValue binds an expression to provide a specific interface type.
//
// Example:
//
// var MySet = wire.NewSet(wire.InterfaceValue(new(io.Reader), os.Stdin))
func InterfaceValue(typ interface{}, x interface{}) ProvidedValue {
return ProvidedValue{}
}