MCPcopy Create free account
hub / github.com/goadesign/goa / transformAttribute

Function transformAttribute

codegen/go_transform.go:79–96  ·  view source on GitHub ↗

transformAttribute returns the code to transform source attribute to target attribute. It returns an error if source and target are not compatible for transformation.

(source, target *expr.AttributeExpr, sourceVar, targetVar string, newVar bool, ta *TransformAttrs)

Source from the content-addressed store, hash-verified

77// attribute. It returns an error if source and target are not compatible for
78// transformation.
79func transformAttribute(source, target *expr.AttributeExpr, sourceVar, targetVar string, newVar bool, ta *TransformAttrs) (code string, err error) {
80 if err = IsCompatible(source.Type, target.Type, sourceVar, targetVar); err != nil {
81 return
82 }
83 switch {
84 case expr.IsArray(source.Type):
85 code, err = transformArray(expr.AsArray(source.Type), expr.AsArray(target.Type), sourceVar, targetVar, newVar, ta)
86 case expr.IsMap(source.Type):
87 code, err = transformMap(expr.AsMap(source.Type), expr.AsMap(target.Type), sourceVar, targetVar, newVar, ta)
88 case expr.IsUnion(source.Type):
89 code, err = transformUnion(source, target, sourceVar, targetVar, newVar, ta)
90 case expr.IsObject(source.Type):
91 code, err = transformObject(source, target, sourceVar, targetVar, newVar, ta)
92 default:
93 code, err = transformPrimitive(source, target, sourceVar, targetVar, newVar, ta)
94 }
95 return
96}
97
98// transformPrimitive returns the code to transform source primtive type to
99// target primitive type. It returns an error if source and target are not

Callers 3

GoTransformFunction · 0.70
transformObjectFunction · 0.70
generateHelperFunction · 0.70

Calls 12

IsArrayFunction · 0.92
AsArrayFunction · 0.92
IsMapFunction · 0.92
AsMapFunction · 0.92
IsUnionFunction · 0.92
IsObjectFunction · 0.92
IsCompatibleFunction · 0.85
transformUnionFunction · 0.85
transformPrimitiveFunction · 0.85
transformArrayFunction · 0.70
transformMapFunction · 0.70
transformObjectFunction · 0.70

Tested by

no test coverage detected