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

[WIP] Support simultanous name and group tags #381

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jquirke
Copy link

@jquirke jquirke commented Mar 6, 2023

As per Dig issue:
#380

In order to support Fx feature requests

uber-go/fx#998
uber-go/fx#1036

We need to be able to drop the restriction, both in terms of options dig.Name and dig.Group and dig.Out struct annotations on name and group being mutually exclusive.

In a shortly upcoming PR, this can then be exploited to populate value group maps where the 'name' tag becomes the key of a map[string][T]

For now, please do not merge.

@CLAassistant
Copy link

CLAassistant commented Mar 6, 2023

CLA assistant check
All committers have signed the CLA.

@jquirke jquirke changed the title Support simultanous name and group tags [WIP] Support simultanous name and group tags Mar 6, 2023
result.go Show resolved Hide resolved
dig_test.go Outdated Show resolved Hide resolved
@jquirke jquirke force-pushed the dig_380 branch 2 times, most recently from 660e806 to 4541e57 Compare March 6, 2023 07:50
result.go Outdated Show resolved Hide resolved
@jquirke jquirke force-pushed the dig_380 branch 3 times, most recently from f3d07ad to 09b8db4 Compare March 9, 2023 07:55
As per Dig issue:
uber-go#380

In order to support Fx feature requests

uber-go/fx#998
uber-go/fx#1036

We need to be able to drop the restriction, both in terms of options
dig.Name and dig.Group and dig.Out struct annotations on `name` and
`group` being mutually exclusive.

In a future PR, this can then be exploited to populate value group maps
where the 'name' tag becomes the key of a map[string][T]
As part of uber-go#380 we allowed names
and groups tags/options to co-exist to ultimately support Fx feature
request uber-go/fx#998.

We now intend to support Map value groups as per
uber-go/fx#1036. We will do this in 2 steps.

1. This PR will begin tracking any names passed into value groups with
out changing any external facing functionality.

2. a subsequent PR will exploit this structure to support Map value
groups.
This revision allows dig to specify value groups of map type.

For example:

```
type Params struct {
	dig.In

	Things      []int          `group:"foogroup"`
	MapOfThings map[string]int `group:"foogroup"`
}
type Result struct {
	dig.Out

	Int1 int `name:"foo1" group:"foogroup"`
	Int2 int `name:"foo2" group:"foogroup"`
	Int3 int `name:"foo3" group:"foogroup"`
}

c.Provide(func() Result {
		return Result{Int1: 1, Int2: 2, Int3: 3}
	})

c.Invoke(func(p Params) {
})
```

p.Things will be a value group slice as per usual, containing the
elements {1,2,3} in an arbitrary order.

p.MapOfThings will be a key-value pairing of
{"foo1":1, "foo2":2, "foo3":3}.
@jquirke jquirke changed the title [WIP] Support simultanous name and group tags Support simultanous name and group tags Mar 19, 2023
@jquirke jquirke changed the title Support simultanous name and group tags [WIP] Support simultanous name and group tags Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants