feat: support bool for env tag (#2593)

This commit is contained in:
Kevin Wan
2022-11-12 13:58:35 +08:00
committed by GitHub
parent 69068cdaf0
commit b562e940e7
2 changed files with 50 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"reflect"
"strconv"
"strings"
"sync"
"time"
@@ -342,6 +343,14 @@ func (u *Unmarshaler) processFieldWithEnvValue(field reflect.StructField, value
envVal string, opts *fieldOptionsWithContext, fullName string) error {
fieldKind := field.Type.Kind()
switch fieldKind {
case reflect.Bool:
val, err := strconv.ParseBool(envVal)
if err != nil {
return fmt.Errorf("unmarshal field %q with environment variable, %w", fullName, err)
}
value.SetBool(val)
return nil
case durationType.Kind():
if err := fillDurationValue(fieldKind, value, envVal); err != nil {
return fmt.Errorf("unmarshal field %q with environment variable, %w", fullName, err)