Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling wire.Build with a provider set from a structure variable (For modular buildings) #375

Open
diegoortizmatajira opened this issue Oct 25, 2022 · 0 comments

Comments

@diegoortizmatajira
Copy link

diegoortizmatajira commented Oct 25, 2022

Describe the bug

I am trying to build a module system to allow some packages to provide their ProviderSets, along with other package settings.
This means having a structure to be filled by each package, then after processing and composing modules, the idea is to have a global module with an aggregation of the required Wire Providers, Bindings, etc.

In the end, instead of passing a single variable with the provider set, we pass a member from a structure variable to the wire.Build call.

Example:

wire.Build(module.ProviderSet)

instead of

wire.Build(providerSet)

But instead of getting the code generated as expected, I got

internal/wiring/wire.go|32 col 19| unknown pattern
internal/wiring/wire_gen.go|3| running "go": exit status 1

To Reproduce

The following code reproduces the issue

//go:build wireinject

package wiring

import (
	"github.com/google/wire"
)

// ClockProvider is a test struct
type ClockProvider struct{}

// This is a Provider function / Constuctor for ClockProvider
func NewProvider() *ClockProvider {
	return &ClockProvider{}
}

// This is a mock of a Module Structure that can
// hold a module settings, providers, default values, etc.
type Module struct {
	Set           wire.ProviderSet
	DefaultValues []string
}

// This is a sample module instance
var myModule = Module{
	Set:           wire.NewSet(NewProvider),
	DefaultValues: []string{"Value 1", "Value 2"},
}

// To be generated
func GetClockProvider() (*ClockProvider, error) {
	panic(wire.Build(myModule.Set))
}

Expected behavior

The generated code should be the same as the one providing a single variable.

Version

  • github.com/google/wire v0.5.0
  • go version go1.19.2 linux/amd64
@diegoortizmatajira diegoortizmatajira changed the title Provider set in a field in a structure (For modular buildings) Calling wire.Build with a provider set from a structure variable (For modular buildings) Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant