GetConversionFunc returns the conversion function for the given input and output types, or an error if no conversion is supported. Will return a no-op conversion if the input and output types are the same.
(t *v1beta1.ConvertTransform, from v1beta1.TransformIOType)
| 431 | // GetConversionFunc returns the conversion function for the given input and output types, or an error if no conversion is |
| 432 | // supported. Will return a no-op conversion if the input and output types are the same. |
| 433 | func GetConversionFunc(t *v1beta1.ConvertTransform, from v1beta1.TransformIOType) (func(any) (any, error), error) { |
| 434 | originalFrom := from |
| 435 | to := t.ToType |
| 436 | if to == v1beta1.TransformIOTypeInt { |
| 437 | to = v1beta1.TransformIOTypeInt64 |
| 438 | } |
| 439 | if from == v1beta1.TransformIOTypeInt { |
| 440 | from = v1beta1.TransformIOTypeInt64 |
| 441 | } |
| 442 | if to == from { |
| 443 | return func(input any) (any, error) { |
| 444 | return input, nil |
| 445 | }, nil |
| 446 | } |
| 447 | f := getConversion(conversionPair{from: from, to: to, format: t.GetFormat()}) |
| 448 | if f == nil { |
| 449 | return nil, errors.Errorf(v1beta1.ErrFmtConvertFormatPairNotSupported, originalFrom, to, t.GetFormat()) |
| 450 | } |
| 451 | return f, nil |
| 452 | } |
| 453 | |
| 454 | // The unparam linter is complaining that these functions always return a nil |
| 455 | // error, but we need this to be the case given some other functions in the map |