MCPcopy Create free account
hub / github.com/crossplane-contrib/function-patch-and-transform / GetConversionFunc

Function GetConversionFunc

transforms.go:433–452  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
433func 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

Callers 2

ResolveConvertFunction · 0.85

Calls 2

getConversionFunction · 0.85
GetFormatMethod · 0.80

Tested by 1