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

Function transformArray

codegen/go_transform.go:387–407  ·  view source on GitHub ↗

transformArray generates Go code to transform source array to target array.

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

Source from the content-addressed store, hash-verified

385
386// transformArray generates Go code to transform source array to target array.
387func transformArray(source, target *expr.Array, sourceVar, targetVar string, newVar bool, ta *TransformAttrs) (string, error) {
388 if err := IsCompatible(source.ElemType.Type, target.ElemType.Type, sourceVar+"[0]", targetVar+"[0]"); err != nil {
389 return "", err
390 }
391 data := map[string]any{
392 "ElemTypeRef": ta.TargetCtx.Scope.Ref(target.ElemType, ta.TargetCtx.Pkg(target.ElemType)),
393 "SourceElem": source.ElemType,
394 "TargetElem": target.ElemType,
395 "SourceVar": sourceVar,
396 "TargetVar": targetVar,
397 "NewVar": newVar,
398 "TransformAttrs": ta,
399 "LoopVar": string(rune(105 + strings.Count(targetVar, "["))),
400 "IsStruct": expr.IsObject(target.ElemType.Type),
401 }
402 var buf bytes.Buffer
403 if err := transformGoArrayT.Execute(&buf, data); err != nil {
404 return "", err
405 }
406 return buf.String(), nil
407}
408
409// transformMap generates Go code to transform source map to target map.
410func transformMap(source, target *expr.Map, sourceVar, targetVar string, newVar bool, ta *TransformAttrs) (string, error) {

Callers 2

transformAttributeFunction · 0.70
transformObjectFunction · 0.70

Calls 7

IsObjectFunction · 0.92
IsCompatibleFunction · 0.85
PkgMethod · 0.80
CountMethod · 0.80
ExecuteMethod · 0.80
RefMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected