GetInt extracts an integer from the map.
(key string)
| 128 | |
| 129 | // GetInt extracts an integer from the map. |
| 130 | func (m StringMap) GetInt(key string) (int64, error) { |
| 131 | val, err := m.Get(key) |
| 132 | if err != nil { |
| 133 | return 0, err |
| 134 | } |
| 135 | |
| 136 | t := reflect.TypeOf(val) |
| 137 | |
| 138 | //nolint:exhaustive |
| 139 | switch t.Kind() { |
| 140 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: |
| 141 | return reflect.ValueOf(val).Int(), nil |
| 142 | default: |
| 143 | return 0, fmt.Errorf("%w: expected an integer, but received %T", errFieldTypeMismatch, val) |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | // GetFloat extracts a float from the map. |
| 148 | func (m StringMap) GetFloat(key string) (float64, error) { |