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

Function getConversion

transforms.go:457–585  ·  view source on GitHub ↗

The unparam linter is complaining that these functions always return a nil error, but we need this to be the case given some other functions in the map may return an error.

(pair conversionPair)

Source from the content-addressed store, hash-verified

455// error, but we need this to be the case given some other functions in the map
456// may return an error.
457func getConversion(pair conversionPair) func(any) (any, error) { //nolint:gocognit // only slightly more complex than desired
458 conversions := map[conversionPair]func(any) (any, error){
459 {from: v1beta1.TransformIOTypeString, to: v1beta1.TransformIOTypeInt64, format: v1beta1.ConvertTransformFormatNone}: func(i any) (any, error) {
460 s, ok := i.(string)
461 if !ok {
462 return nil, errors.Errorf(errFmtConvertInputTypeNotSupported, i)
463 }
464 return strconv.ParseInt(s, 10, 64)
465 },
466 {from: v1beta1.TransformIOTypeString, to: v1beta1.TransformIOTypeBool, format: v1beta1.ConvertTransformFormatNone}: func(i any) (any, error) {
467 s, ok := i.(string)
468 if !ok {
469 return nil, errors.Errorf(errFmtConvertInputTypeNotSupported, i)
470 }
471 return strconv.ParseBool(s)
472 },
473 {from: v1beta1.TransformIOTypeString, to: v1beta1.TransformIOTypeFloat64, format: v1beta1.ConvertTransformFormatNone}: func(i any) (any, error) {
474 s, ok := i.(string)
475 if !ok {
476 return nil, errors.Errorf(errFmtConvertInputTypeNotSupported, i)
477 }
478 return strconv.ParseFloat(s, 64)
479 },
480 {from: v1beta1.TransformIOTypeString, to: v1beta1.TransformIOTypeFloat64, format: v1beta1.ConvertTransformFormatQuantity}: func(i any) (any, error) {
481 s, ok := i.(string)
482 if !ok {
483 return nil, errors.Errorf(errFmtConvertInputTypeNotSupported, i)
484 }
485 q, err := resource.ParseQuantity(s)
486 if err != nil {
487 return nil, err
488 }
489 return q.AsApproximateFloat64(), nil
490 },
491
492 {from: v1beta1.TransformIOTypeInt64, to: v1beta1.TransformIOTypeString, format: v1beta1.ConvertTransformFormatNone}: func(i any) (any, error) {
493 s, ok := i.(int64)
494 if !ok {
495 return nil, errors.Errorf(errFmtConvertInputTypeNotSupported, i)
496 }
497 return strconv.FormatInt(s, 10), nil
498 },
499 {from: v1beta1.TransformIOTypeInt64, to: v1beta1.TransformIOTypeBool, format: v1beta1.ConvertTransformFormatNone}: func(i any) (any, error) {
500 s, ok := i.(int64)
501 if !ok {
502 return nil, errors.Errorf(errFmtConvertInputTypeNotSupported, i)
503 }
504 return s == 1, nil
505 },
506 {from: v1beta1.TransformIOTypeInt64, to: v1beta1.TransformIOTypeFloat64, format: v1beta1.ConvertTransformFormatNone}: func(i any) (any, error) {
507 s, ok := i.(int64)
508 if !ok {
509 return nil, errors.Errorf(errFmtConvertInputTypeNotSupported, i)
510 }
511 return float64(s), nil
512 },
513
514 {from: v1beta1.TransformIOTypeBool, to: v1beta1.TransformIOTypeString, format: v1beta1.ConvertTransformFormatNone}: func(i any) (any, error) {

Callers 1

GetConversionFuncFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected