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

dig.In/Out: Allow and ignore unexported fields #273

Closed
abhinav opened this issue Feb 16, 2021 · 0 comments · Fixed by #274
Closed

dig.In/Out: Allow and ignore unexported fields #273

abhinav opened this issue Feb 16, 2021 · 0 comments · Fixed by #274
Assignees

Comments

@abhinav
Copy link
Collaborator

abhinav commented Feb 16, 2021

dig.In and dig.Out structs explicitly disallow unexported fields on their
structs.

dig/param.go

Line 349 in 4ea2499

"unexported fields not allowed in dig.In, did you mean to export %q (%v)?",

Based on anecdotal evidence from our internal support room, this check makes
sense because otherwise users will assume that those unexported fields will
also be filled by Fx.

However, there's value in allowing unexported fields on dig.In tagged structs
regardless, e.g. uber-go/fx#673. We may want to
support an opt-in means of specifying that a provided struct MAY have
unexported fields.

One means of doing this is struct tags on the embedded dig.In field:

type foo struct {
  dig.In `allow-unexported:"true"`  // naming TBD
  
  Foo Foo
  bar bar // ignored by Dig
}

Internal issue reference: GO-374

@manjari25 manjari25 self-assigned this Feb 23, 2021
manjari25 added a commit to manjari25/dig that referenced this issue Feb 23, 2021
In order for unexported fields to be allowed, an 
"allowUnexported=true" struct tag should be used on the embedded dig.In 
field.

Resolves: uber-go#273
abhinav pushed a commit that referenced this issue Mar 1, 2021
In order for unexported fields to be allowed, add support for an
`ignore-unexported:"true"` struct tag on the embedded `dig.In` field.

Resolves #273
abhinav added a commit to uber-go/fx that referenced this issue Jun 4, 2021
This adds support for `ignore-unexported` (uber-go/dig#273,
uber-go/dig#274) to Fx.

To add support, we merely need to bump the minimum version constraint to
a version of dig that has this feature.

Until the version is released, we're adding a `replace` directive
instead.

Refs GO-374
abhinav added a commit to uber-go/fx that referenced this issue Jun 9, 2021
This adds support for `ignore-unexported` (uber-go/dig#273,
uber-go/dig#274) to Fx.

To add support, we merely need to bump the minimum version constraint to
a version of dig that has this feature.

Until the version is released, we're adding a `replace` directive
instead.

Refs GO-374
abhinav added a commit to uber-go/fx that referenced this issue Jun 9, 2021
This adds support for `ignore-unexported` (uber-go/dig#273,
uber-go/dig#274) to Fx.

To add support, we merely need to bump the minimum version constraint to
a version of dig that has this feature.

Refs GO-374
abhinav added a commit to uber-go/fx that referenced this issue Jun 14, 2021
This adds support for `ignore-unexported` (uber-go/dig#273,
uber-go/dig#274) to Fx.

To add support, we merely need to bump the minimum version constraint to
a version of dig that has this feature.

Refs GO-374
luoboton added a commit to luoboton/fx that referenced this issue Aug 24, 2022
This adds support for `ignore-unexported` (uber-go/dig#273,
uber-go/dig#274) to Fx.

To add support, we merely need to bump the minimum version constraint to
a version of dig that has this feature.

Refs GO-374
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants