|
30 | 30 | errValueNotSettable = errors.New("value is not settable") |
31 | 31 | errValueNotStruct = errors.New("value type is not struct") |
32 | 32 | keyUnmarshaler = NewUnmarshaler(defaultKeyName) |
| 33 | + boolType = reflect.TypeOf(false) |
33 | 34 | durationType = reflect.TypeOf(time.Duration(0)) |
| 35 | + stringType = reflect.TypeOf("") |
34 | 36 | cacheKeys = make(map[string][]string) |
35 | 37 | cacheKeysLock sync.Mutex |
36 | 38 | defaultCache = make(map[string]any) |
@@ -765,24 +767,24 @@ func (u *Unmarshaler) processFieldWithEnvValue(fieldType reflect.Type, value ref |
765 | 767 | return err |
766 | 768 | } |
767 | 769 |
|
768 | | - fieldKind := fieldType.Kind() |
769 | | - switch true { |
770 | | - case fieldKind == reflect.Bool: |
| 770 | + derefType := Deref(fieldType) |
| 771 | + switch derefType { |
| 772 | + case boolType: |
771 | 773 | val, err := strconv.ParseBool(envVal) |
772 | 774 | if err != nil { |
773 | 775 | return fmt.Errorf("unmarshal field %q with environment variable, %w", fullName, err) |
774 | 776 | } |
775 | 777 |
|
776 | | - value.SetBool(val) |
| 778 | + SetValue(fieldType, value, reflect.ValueOf(val)) |
777 | 779 | return nil |
778 | | - case fieldType == durationType: |
| 780 | + case durationType: |
779 | 781 | if err := fillDurationValue(fieldType, value, envVal); err != nil { |
780 | 782 | return fmt.Errorf("unmarshal field %q with environment variable, %w", fullName, err) |
781 | 783 | } |
782 | 784 |
|
783 | 785 | return nil |
784 | | - case fieldKind == reflect.String: |
785 | | - value.SetString(envVal) |
| 786 | + case stringType: |
| 787 | + SetValue(fieldType, value, reflect.ValueOf(envVal)) |
786 | 788 | return nil |
787 | 789 | default: |
788 | 790 | return u.processFieldPrimitiveWithJSONNumber(fieldType, value, json.Number(envVal), opts, fullName) |
|
0 commit comments