-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
feat(depinject): support ignored fields in input structs #22409
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,6 +113,13 @@ func structArgsInTypes(typ reflect.Type) ([]providerInput, error) { | |
continue | ||
} | ||
|
||
var ignored bool | ||
_, found := f.Tag.Lookup("ignored") | ||
if found { | ||
continue | ||
// ignored = true | ||
} | ||
|
||
var optional bool | ||
optTag, found := f.Tag.Lookup("optional") | ||
if found { | ||
|
@@ -126,6 +133,7 @@ func structArgsInTypes(typ reflect.Type) ([]providerInput, error) { | |
res = append(res, providerInput{ | ||
Type: f.Type, | ||
Optional: optional, | ||
Ignored: ignored, | ||
}) | ||
} | ||
return res, nil | ||
|
@@ -170,6 +178,11 @@ func buildIn(typ reflect.Type, values []reflect.Value) (reflect.Value, int, erro | |
if f.Type.AssignableTo(isInType) { | ||
continue | ||
} | ||
_, found := f.Tag.Lookup("ignored") | ||
if found { | ||
continue | ||
} | ||
|
||
Comment on lines
+180
to
+184
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider extracting the ignored tag check into a helper function. The ignored tag check is duplicated between +func isIgnoredField(f reflect.StructField) bool {
+ _, found := f.Tag.Lookup("ignored")
+ return found
+}
func buildIn(typ reflect.Type, values []reflect.Value) (reflect.Value, int, error) {
// ...
- _, found := f.Tag.Lookup("ignored")
- if found {
+ if isIgnoredField(f) {
continue
}
// ...
}
func structArgsInTypes(typ reflect.Type) ([]providerInput, error) {
// ...
- _, found := f.Tag.Lookup("ignored")
- if found {
+ if isIgnoredField(f) {
continue
}
// ...
}
|
||
if !res.Elem().Field(i).CanSet() { | ||
return reflect.Value{}, 0, fmt.Errorf("depinject.In struct %s on package %s can't have unexported field", res.Elem().String(), f.PkgPath) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Enhance test coverage with additional assertions
While the test verifies successful injection, it should also validate:
Consider enhancing the test with these assertions:
📝 Committable suggestion