wire
wire copied to clipboard
wire: add "subtract" command
If someone wants to "override" a set of providers from a larger set, it would be helpful to have the gowire tool output the minimal code to create a new provider set that "carves out" the given provider from the set. Ideal workflow:
$ gowire subtract github.com/google/go-cloud/gcp/gcpcloud.GCP github.com/google/go-cloud/gcp.ProjectID
import (
"github.com/google/go-cloud/gcp"
"github.com/google/go-cloud/gcp/gcpcloud"
"github.com/google/go-cloud/wire"
)
var Set = wire.NewSet(
gcpcloud.Services,
gcp.CredentialsTokenSource,
gcp.DefaultCredentials,
)
Perhaps this would include an interactive mode that shows you everything in the provider set and lets you pick which types to remove by menu, since typing type names is arduous.
Another idea is to have wire.Subtract be a wire directive, used to wrap a ProviderSet in a wire.NewSet or a wire.Build.
Use cases might be:
- I want to make a
SetAB that unions 2 other sets A and B, but there's a type T that's the same between A and B.
var SetAB = wire.NewSet(A, B)
- Today, you'd get an error that there's two providers for T and you'd be kind of hosed.
- With
wire.Subtract, you could do:
var SetAB = wire.NewSet(A, wire.Subtract(B, T))
- I want to use an existing
ProviderSet, but want to override one of the types it provides. For example, azureblob defines a Set that hasNewPipelineandOptions{}in it. Today, this code would produce an error becauseOptionsis provided twice, once by the injector function parameter and once byazureblob.Set.
func azureBucket(bucketName string, opts *azureblob.Options) *blob.Bucket {
wire.Build(
azureblob.DefaultIdentity,
azureblob.Set,
)
Again, you'd be kind of hosed; you'd have to explicitly add all of the providers in azureblob.Set that you need. With wire.Subtract, you would do:
func azureBucket(bucketName string, opts *azureblob.Options) *blob.Bucket {
wire.Build(
azureblob.DefaultIdentity,
wire.Subtract(azureblob.Set, azureblob.Options),
)
@zombiezen Any chance this will be worked on? Will a PR be accepted if I implement this? This one seems useful for mocking purpose for me.
I have same issue here, Just want to change the timeout value in the default server's driver. :(
This seems reasonable to me, but I haven't been working on Wire for a while. @vangent, WDYT?
@eliben can you add the new owners for this repo?
wire.Subtract sounds good, I'm happy to help review and merge a PR (new owner here :D)