GetFloat extracts a float from the map.
(key string)
| 146 | |
| 147 | // GetFloat extracts a float from the map. |
| 148 | func (m StringMap) GetFloat(key string) (float64, error) { |
| 149 | val, err := m.Get(key) |
| 150 | if err != nil { |
| 151 | return 0, err |
| 152 | } |
| 153 | |
| 154 | t := reflect.TypeOf(val) |
| 155 | |
| 156 | //nolint:exhaustive |
| 157 | switch t.Kind() { |
| 158 | case reflect.Float32, reflect.Float64: |
| 159 | return reflect.ValueOf(val).Float(), nil |
| 160 | default: |
| 161 | return 0, fmt.Errorf("%w: expected a float, but received %T", errFieldTypeMismatch, val) |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | func (m StringMap) GetNumber(key string) (float64, error) { |
| 166 | val, err := m.Get(key) |