(v varInfo)
| 307 | } |
| 308 | |
| 309 | func parseValue(v varInfo) (types.Val, error) { |
| 310 | typ := v.Type |
| 311 | if v.Value == "" { |
| 312 | return types.Val{}, errors.Errorf("No value found") |
| 313 | } |
| 314 | |
| 315 | switch typ { |
| 316 | case "int": |
| 317 | { |
| 318 | if i, err := strconv.ParseInt(v.Value, 0, 64); err != nil { |
| 319 | return types.Val{}, errors.Wrapf(err, "Expected an int but got %v", v.Value) |
| 320 | } else { |
| 321 | return types.Val{ |
| 322 | Tid: types.IntID, |
| 323 | Value: i, |
| 324 | }, nil |
| 325 | } |
| 326 | } |
| 327 | case "float": |
| 328 | { |
| 329 | if i, err := strconv.ParseFloat(v.Value, 64); err != nil { |
| 330 | return types.Val{}, errors.Wrapf(err, "Expected a float but got %v", v.Value) |
| 331 | } else { |
| 332 | return types.Val{ |
| 333 | Tid: types.FloatID, |
| 334 | Value: i, |
| 335 | }, nil |
| 336 | } |
| 337 | } |
| 338 | case "bool": |
| 339 | { |
| 340 | if i, err := strconv.ParseBool(v.Value); err != nil { |
| 341 | return types.Val{}, errors.Wrapf(err, "Expected a bool but got %v", v.Value) |
| 342 | } else { |
| 343 | return types.Val{ |
| 344 | Tid: types.BoolID, |
| 345 | Value: i, |
| 346 | }, nil |
| 347 | } |
| 348 | } |
| 349 | case "float32vector": |
| 350 | { |
| 351 | if i, err := types.ParseVFloat(v.Value); err != nil { |
| 352 | return types.Val{}, errors.Wrapf(err, "Expected a float32vector but got %v", v.Value) |
| 353 | } else { |
| 354 | return types.Val{ |
| 355 | Tid: types.VFloatID, |
| 356 | Value: i, |
| 357 | }, nil |
| 358 | } |
| 359 | } |
| 360 | case "string": // Value is a valid string. No checks required. |
| 361 | return types.Val{ |
| 362 | Tid: types.StringID, |
| 363 | Value: v.Value, |
| 364 | }, nil |
| 365 | default: |
| 366 | return types.Val{}, errors.Errorf("Type %q not supported", typ) |
no test coverage detected