Skip to content

Commit f37b8ea

Browse files
Expose CompareStruct to templates (#231)
Description of changes: Exports and exposes the `CompareStruct` method, so that hooks can create their own delta comparison code. This PR will also require #229 as the delta code could require importing `reflect` By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 18843e6 commit f37b8ea

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

pkg/generate/ack/controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ var (
107107
"GoCodeCompare": func(r *ackmodel.CRD, deltaVarName string, sourceVarName string, targetVarName string, indentLevel int) string {
108108
return code.CompareResource(r.Config(), r, deltaVarName, sourceVarName, targetVarName, indentLevel)
109109
},
110+
"GoCodeCompareStruct": func(r *ackmodel.CRD, shape *awssdkmodel.Shape, deltaVarName string, sourceVarName string, targetVarName string, fieldPath string, indentLevel int) string {
111+
return code.CompareStruct(r.Config(), r, nil, shape, deltaVarName, sourceVarName, targetVarName, fieldPath, indentLevel)
112+
},
110113
"Empty": func(subject string) bool {
111114
return strings.TrimSpace(subject) == ""
112115
},

pkg/generate/code/compare.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func CompareResource(
157157
case "structure":
158158
// Recurse through all the struct's fields and subfields, building
159159
// nested conditionals and calls to `delta.Add()`...
160-
out += compareStruct(
160+
out += CompareStruct(
161161
cfg, r,
162162
compareConfig,
163163
memberShape,
@@ -501,10 +501,10 @@ func compareSlice(
501501
return out
502502
}
503503

504-
// compareStruct outputs Go code that compares two struct values from two
504+
// CompareStruct outputs Go code that compares two struct values from two
505505
// resource fields and, if there is a difference, adds the difference to a
506506
// variable representing an `ackcompare.Delta`.
507-
func compareStruct(
507+
func CompareStruct(
508508
cfg *ackgenconfig.Config,
509509
r *model.CRD,
510510
// struct informing code generator how to compare the field values
@@ -586,7 +586,7 @@ func compareStruct(
586586
case "structure":
587587
// Recurse through all the struct's fields and subfields, building
588588
// nested conditionals and calls to `delta.Add()`...
589-
out += compareStruct(
589+
out += CompareStruct(
590590
cfg, r,
591591
compareConfig,
592592
memberShape,

0 commit comments

Comments
 (0)