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)
| 54 | // using `:=` operator. If false, it assigns Go code to the target variable |
| 55 | // using `=`. |
| 56 | func 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 |