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

Function GoTransform

codegen/go_transform.go:56–74  ·  view source on GitHub ↗

GoTransform produces Go code that initializes the data structure defined by target from an instance of the data structure described by source. The data structures can be objects, arrays or maps. The algorithm matches object fields by name and ignores object fields in target that don't have a match i

(source, target *expr.AttributeExpr, sourceVar, targetVar string, sourceCtx, targetCtx *AttributeContext, prefix string, newVar bool)

Source from the content-addressed store, hash-verified

54// using `:=` operator. If false, it assigns Go code to the target variable
55// using `=`.
56func GoTransform(source, target *expr.AttributeExpr, sourceVar, targetVar string, sourceCtx, targetCtx *AttributeContext, prefix string, newVar bool) (string, []*TransformFunctionData, error) {
57 ta := &TransformAttrs{
58 SourceCtx: sourceCtx,
59 TargetCtx: targetCtx,
60 Prefix: prefix,
61 }
62
63 code, err := transformAttribute(source, target, sourceVar, targetVar, newVar, ta)
64 if err != nil {
65 return "", nil, err
66 }
67
68 funcs, err := transformAttributeHelpers(source, target, ta, make(map[string]*TransformFunctionData))
69 if err != nil {
70 return "", nil, err
71 }
72
73 return strings.TrimRight(code, "\n"), funcs, nil
74}
75
76// transformAttribute returns the code to transform source attribute to target
77// attribute. It returns an error if source and target are not compatible for

Callers 10

unmarshalFunction · 0.92
marshalFunction · 0.92
ConvertFileFunction · 0.92
buildConstructorCodeFunction · 0.92
TestGoTransformUnionFunction · 0.85
InitStructFieldsFunction · 0.85
TestGoTransformFunction · 0.85
TestGoTransformHelpersFunction · 0.85

Calls 2

transformAttributeFunction · 0.70

Tested by 4

TestGoTransformUnionFunction · 0.68
TestGoTransformFunction · 0.68
TestGoTransformHelpersFunction · 0.68