initializeFromPositionalArgs initializes struct fields from positional arguments
(instance interface{}, args []*Value, typ reflect.Type, ctx *Context)
| 185 | |
| 186 | // initializeFromPositionalArgs initializes struct fields from positional arguments |
| 187 | func initializeFromPositionalArgs(instance interface{}, args []*Value, typ reflect.Type, ctx *Context) error { |
| 188 | val := reflect.ValueOf(instance).Elem() // Dereference pointer to get struct value |
| 189 | |
| 190 | argIndex := 0 |
| 191 | for i := 0; i < typ.NumField(); i++ { |
| 192 | field := typ.Field(i) |
| 193 | |
| 194 | // Skip unexported fields |
| 195 | if !field.IsExported() { |
| 196 | continue |
| 197 | } |
| 198 | |
| 199 | // Break if no more arguments |
| 200 | if argIndex >= len(args) { |
| 201 | break |
| 202 | } |
| 203 | |
| 204 | fieldValue := val.Field(i) |
| 205 | if fieldValue.CanSet() { |
| 206 | if err := ctx.unmarshal(args[argIndex], fieldValue); err != nil { |
| 207 | return fmt.Errorf("failed to set field %s: %w", field.Name, err) |
| 208 | } |
| 209 | argIndex++ |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | return nil |
| 214 | } |
| 215 | |
| 216 | // initializeFromObjectArgs initializes struct fields from object properties (named parameters) |
| 217 | func initializeFromObjectArgs(instance interface{}, obj *Value, typ reflect.Type, ctx *Context) error { |
no test coverage detected