MCPcopy Create free account
hub / github.com/kataras/iris / fromStructValueOrDependentStructValue

Function fromStructValueOrDependentStructValue

hero/dependency.go:188–266  ·  view source on GitHub ↗
(v reflect.Value, disablePayloadAutoBinding bool, dest *Dependency, prevDependencies []*Dependency)

Source from the content-addressed store, hash-verified

186}
187
188func fromStructValueOrDependentStructValue(v reflect.Value, disablePayloadAutoBinding bool, dest *Dependency, prevDependencies []*Dependency) bool {
189 if !isStructValue(v) {
190 // It's not just a static struct value.
191 return false
192 }
193
194 if len(prevDependencies) == 0 || !dest.StructDependents { // As a non depedent struct.
195 // We must make this check so we can avoid the auto-filling of
196 // the dependencies from Iris builtin dependencies.
197 return fromStructValue(v, dest)
198 }
199
200 // Check if it's a builtin dependency (e.g an MVC Application (see mvc.go#newApp)),
201 // if it's and registered without a Dependency wrapper, like the rest builtin dependencies,
202 // then do NOT try to resolve its fields.
203 //
204 // Although EnableStructDependents is false by default, we must check if it's a builtin dependency for any case.
205 if strings.HasPrefix(indirectType(v.Type()).PkgPath(), "github.com/kataras/iris/v12") {
206 return fromStructValue(v, dest)
207 }
208
209 bindings := getBindingsForStruct(v, prevDependencies, false, disablePayloadAutoBinding, dest.StructDependents, DefaultDependencyMatcher, -1, nil)
210 if len(bindings) == 0 {
211 return fromStructValue(v, dest) // same as above.
212 }
213
214 // As a depedent struct, however we may need to resolve its dependencies first
215 // so we can decide if it's really a depedent struct or not.
216 var (
217 handler = func(*context.Context, *Input) (reflect.Value, error) {
218 return v, nil
219 }
220 isStatic = true
221 )
222
223 for _, binding := range bindings {
224 if !binding.Dependency.Static {
225 isStatic = false
226 break
227 }
228 }
229
230 handler = func(ctx *context.Context, _ *Input) (reflect.Value, error) { // Called once per dependency on build-time if the dependency is static.
231 elem := v
232 if elem.Kind() == reflect.Ptr {
233 elem = elem.Elem()
234 }
235
236 for _, binding := range bindings {
237 field := elem.FieldByIndex(binding.Input.StructFieldIndex)
238 if !field.CanSet() || !field.IsZero() {
239 continue // already set.
240 }
241 // if !binding.Dependency.Match(field.Type()) { A check already happen in getBindingsForStruct.
242 // continue
243 // }
244
245 input, err := binding.Dependency.Handle(ctx, binding.Input)

Callers 1

resolveDependencyFunction · 0.85

Calls 8

isStructValueFunction · 0.85
fromStructValueFunction · 0.85
getBindingsForStructFunction · 0.85
TypeMethod · 0.80
indirectTypeFunction · 0.70
IsZeroMethod · 0.65
HandleMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…