github.com/twilio/twilio-go@v1.20.1/client/unmarshal.go (about) 1 package client 2 3 import ( 4 "fmt" 5 "strconv" 6 ) 7 8 func UnmarshalFloat32(input *interface{}) (*float32, error) { 9 if input == nil { 10 return nil, nil 11 } 12 13 switch value := (*input).(type) { 14 case float32: 15 return &value, nil 16 case float64: 17 value32 := float32(value) 18 return &value32, nil 19 case int: 20 value32 := float32(value) 21 return &value32, nil 22 case string: 23 parsed, err := strconv.ParseFloat(value, 32) 24 if err != nil { 25 return nil, err 26 } 27 value32 := float32(parsed) 28 return &value32, nil 29 default: 30 return nil, fmt.Errorf("unhandled input type for float32: %T %#v", value, value) 31 } 32 }