GetFloat retrieves a float64 value from the options. If the key does not exist, GetFloat returns the provided default value. If the key value exists but the value is of a different float or integer type, GetFloat converts it to float64. If the key exists but the value is not a float or integer type,
(key string, def float64)
| 235 | // GetFloat converts it to float64. |
| 236 | // If the key exists but the value is not a float or integer type, GetFloat panics. |
| 237 | func (o *Options) GetFloat(key string, def float64) float64 { |
| 238 | v, ok := o.m[key] |
| 239 | if !ok { |
| 240 | return def |
| 241 | } |
| 242 | |
| 243 | switch t := v.(type) { |
| 244 | case int: |
| 245 | return float64(t) |
| 246 | case int8: |
| 247 | return float64(t) |
| 248 | case int16: |
| 249 | return float64(t) |
| 250 | case int32: |
| 251 | return float64(t) |
| 252 | case int64: |
| 253 | return float64(t) |
| 254 | case uint: |
| 255 | return float64(t) |
| 256 | case uint8: |
| 257 | return float64(t) |
| 258 | case uint16: |
| 259 | return float64(t) |
| 260 | case uint32: |
| 261 | return float64(t) |
| 262 | case uint64: |
| 263 | return float64(t) |
| 264 | case float32: |
| 265 | return float64(t) |
| 266 | case float64: |
| 267 | return t |
| 268 | default: |
| 269 | panic(newTypeMismatchError(key, v, def)) |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | // GetString retrieves a string value. |
| 274 | // If the key doesn't exist, it returns the provided default value. |