generateCompileGuard generates compile-time checks to ensure struct definitions haven't changed since code generation. If a struct is modified, users must re-run go generate or compilation will fail.
(structs []StructInfo)
| 29 | // haven't changed since code generation. If a struct is modified, users must |
| 30 | // re-run go generate or compilation will fail. |
| 31 | func generateCompileGuard(structs []StructInfo) string { |
| 32 | if len(structs) == 0 { |
| 33 | return "" |
| 34 | } |
| 35 | |
| 36 | var buf bytes.Buffer |
| 37 | |
| 38 | buf.WriteString("\n// Compile-time guards: These ensure struct definitions haven't changed\n") |
| 39 | buf.WriteString("// since code generation. If you modify structs, re-run go generate.\n\n") |
| 40 | |
| 41 | for _, structInfo := range structs { |
| 42 | generateStructGuard(&buf, structInfo) |
| 43 | } |
| 44 | |
| 45 | return buf.String() |
| 46 | } |
| 47 | |
| 48 | func generateStructGuard(buf *bytes.Buffer, structInfo StructInfo) { |
| 49 | typeName := structInfo.Name |
no test coverage detected