Acquire returns a struct value based on the request. If the dependencies are all static then these are already set-ed at the initialization of this Struct and the same struct value instance will be returned, ignoring the Context. Otherwise a new struct value with filled fields by its pre-calculated
(ctx *context.Context)
| 141 | // and the same struct value instance will be returned, ignoring the Context. Otherwise |
| 142 | // a new struct value with filled fields by its pre-calculated bindings will be returned instead. |
| 143 | func (s *Struct) Acquire(ctx *context.Context) (reflect.Value, error) { |
| 144 | if s.Singleton { |
| 145 | ctx.Values().Set(context.ControllerContextKey, s.ptrValue) |
| 146 | return s.ptrValue, nil |
| 147 | } |
| 148 | |
| 149 | ctrl := ctx.Controller() |
| 150 | if ctrl.Kind() == reflect.Invalid || |
| 151 | ctrl.Type() != s.ptrType /* in case of changing controller in the same request (see RouteOverlap feature) */ { |
| 152 | ctrl = reflect.New(s.elementType) |
| 153 | ctx.Values().Set(context.ControllerContextKey, ctrl) |
| 154 | elem := ctrl.Elem() |
| 155 | for _, b := range s.bindings { |
| 156 | input, err := b.Dependency.Handle(ctx, b.Input) |
| 157 | if err != nil { |
| 158 | if err == ErrSeeOther { |
| 159 | continue |
| 160 | } |
| 161 | |
| 162 | s.Container.GetErrorHandler(ctx).HandleError(ctx, err) |
| 163 | |
| 164 | if ctx.IsStopped() { |
| 165 | // return emptyValue, err |
| 166 | return ctrl, err |
| 167 | } // #1629 |
| 168 | } |
| 169 | |
| 170 | elem.FieldByIndex(b.Input.StructFieldIndex).Set(input) |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | return ctrl, nil |
| 175 | } |
| 176 | |
| 177 | // MethodHandler accepts a "methodName" that should be a valid an exported |
| 178 | // method of the struct and returns its converted Handler. |
nothing calls this directly
no test coverage detected