in reify.go [307:357]
func reifyGetField(
cfg *Config,
opts fieldOptions,
name string,
to reflect.Value,
fieldType reflect.Type,
) Error {
p := parsePathWithOpts(name, opts.opts)
value, err := p.GetValue(cfg, opts.opts)
if err != nil {
if err.Reason() != ErrMissing {
return err
}
value = nil
}
if isNil(value) {
// When fieldType is a pointer and the value is nil, return nil as the
// underlying type should not be allocated.
if fieldType.Kind() == reflect.Ptr {
if err := tryRecursiveValidate(to, opts.opts, opts.validators); err != nil {
return raiseValidation(cfg.ctx, cfg.metadata, name, err)
}
return nil
}
// Primitive types return early when it doesn't implement the Initializer interface.
if fieldType.Kind() != reflect.Struct && !hasInitDefaults(fieldType) {
if err := tryRecursiveValidate(to, opts.opts, opts.validators); err != nil {
return raiseValidation(cfg.ctx, cfg.metadata, name, err)
}
return nil
}
// None primitive types always get initialized even if it doesn't implement the
// Initializer interface, because nested types might implement the Initializer interface.
if value == nil {
value = &cfgNil{cfgPrimitive{cfg.ctx, cfg.metadata}}
}
}
v, err := reifyMergeValue(opts, to, value)
if err != nil {
return err
}
if v.IsValid() {
to.Set(pointerize(to.Type(), v.Type(), v))
}
return nil
}