-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.go
More file actions
761 lines (639 loc) · 19.4 KB
/
helpers.go
File metadata and controls
761 lines (639 loc) · 19.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
package generator
import (
"fmt"
"log"
"os"
"path/filepath"
"regexp"
"strings"
"unicode"
"github.com/jinzhu/inflection"
"golang.org/x/tools/imports"
"mvdan.cc/gofumpt/format"
)
func toSnakeCase(s string) string {
res := make([]rune, 0, len(s))
for i, r := range s {
if i > 0 && r >= 'A' && r <= 'Z' {
// Check if previous was also uppercase (e.g. ID)
prev := rune(s[i-1])
if prev < 'A' || prev > 'Z' {
res = append(res, '_')
}
}
res = append(res, unicode.ToLower(r))
}
return string(res)
}
func quote(e Engine, s string) string {
if e.IsMySQL() {
return "`" + s + "`"
}
return `\"` + s + `\"`
}
func extractBulkFor(comment string) string {
parts := strings.Fields(comment)
for i, p := range parts {
if p == "@bulk-for" && i+1 < len(parts) {
return parts[i+1]
}
}
return ""
}
func toSingular(s string) string { return inflection.Singular(s) }
// FixAcronyms corrects common Go acronym casing issues using word-boundary-aware
// regex replacements to avoid corrupting words that contain acronyms as substrings.
// For example: Id -> ID, Api -> API, Sql -> SQL, Url -> URL, Xml -> XML.
func FixAcronyms(content []byte) []byte {
// Common Go acronyms that should be all caps, with their correct form.
acronyms := []struct {
pattern string
replacement string
}{
{"Acl", "ACL"},
{"Api", "API"},
{"Cpu", "CPU"},
{"Ec2", "EC2"},
{"Ebs", "EBS"},
{"Html", "HTML"},
{"Id", "ID"},
{"Io", "IO"},
{"Ip", "IP"},
{"Json", "JSON"},
{"Jwt", "JWT"},
{"Sql", "SQL"},
{"Ssh", "SSH"},
{"Tcp", "TCP"},
{"Tls", "TLS"},
{"Udp", "UDP"},
{"Url", "URL"},
{"Xml", "XML"},
}
result := string(content)
for _, a := range acronyms {
// Pre-compile regexes once per acronym (not inside inner loop).
// Use patterns to handle acronyms in different positions:
// 1. Start: `^(Acronym)([A-Z])` - acronym at start followed by uppercase, e.g., Xml in XMLParser.
// 2. AfterUpper: `([A-Z])(Acronym)([A-Z])` - acronym between uppercase, e.g., Html in UserHTMLDoc.
// 3. Mid: `([a-z])(Acronym)([A-Z])` - acronym in middle of camelCase, e.g., Id in userIdMore.
// 4. End: `([a-z])(Acronym)$` - acronym at end of identifier, e.g., Id in userId.
// 5. NonLetter: `([a-z])(Acronym)([^A-Za-z])` - acronym followed by non-letter.
regexStart := regexp.MustCompile(`^(` + a.pattern + `)([A-Z])`)
regexAfterUpper := regexp.MustCompile(`([A-Z])(` + a.pattern + `)([A-Z])`)
regexMid := regexp.MustCompile(`([a-z])(` + a.pattern + `)([A-Z])`)
regexEnd := regexp.MustCompile(`([a-z])(` + a.pattern + `)$`)
regexNonLetter := regexp.MustCompile(`([a-z])(` + a.pattern + `)([^A-Za-z])`)
// Start case: replace with replacement followed by ${2} (the uppercase after).
result = regexStart.ReplaceAllString(result, a.replacement+"${2}")
// After uppercase case: preserve surrounding uppercase via ${1} and ${3}.
result = regexAfterUpper.ReplaceAllString(result, "${1}"+a.replacement+"${3}")
// Middle case: preserve the following uppercase letter via ${3}.
result = regexMid.ReplaceAllString(result, "${1}"+a.replacement+"${3}")
// Non-letter case: preserve the following character via ${3}.
result = regexNonLetter.ReplaceAllString(result, "${1}"+a.replacement+"${3}")
// End case: no ${3} since there's no following letter.
result = regexEnd.ReplaceAllString(result, "${1}"+a.replacement)
}
return []byte(result)
}
func writeFile(dir, filename string, content []byte) {
// 1. Manage imports with goimports
withImports, err := imports.Process(filename, content, nil)
if err != nil {
log.Println(string(content))
log.Fatalf("imports.Process %s: %v", filename, err)
}
// 2. Format with gofumpt
formatted, err := format.Source(withImports, format.Options{
LangVersion: "",
ExtraRules: true,
})
if err != nil {
log.Println(string(withImports))
log.Fatalf("formatting %s: %v", filename, err)
}
// 3. Fix acronym casing (Api -> API, Id -> ID, etc.)
fixed := FixAcronyms(formatted)
if err := os.WriteFile(filepath.Join(dir, filename), fixed, 0o644); err != nil { //nolint:gosec
log.Fatal(err)
}
fmt.Printf("Generated %s\n", filename)
}
// hasParam checks if a parameter with the given name exists in the params list.
func hasParam(name string, params []Param) bool {
for _, param := range params {
if param.Name == name {
return true
}
}
return false
}
func paramHasField(paramName string, fieldName string, params []Param, structs map[string]StructInfo) bool {
for _, param := range params {
if param.Name == paramName {
typeName := strings.TrimPrefix(param.Type, "[]")
typeName = strings.TrimPrefix(typeName, "*")
typeParts := strings.Split(typeName, ".")
if len(typeParts) > 1 {
typeName = typeParts[len(typeParts)-1]
}
if s, ok := structs[typeName]; ok {
for _, f := range s.Fields {
if f.Name == fieldName {
return true
}
}
}
return false
}
}
return false
}
func joinParamsSignature(params []Param) string {
p := make([]string, 0, len(params))
for _, param := range params {
p = append(p, fmt.Sprintf("%s %s", param.Name, param.Type))
}
return strings.Join(p, ", ")
}
// JoinParamsCall is exported for use in tests.
func JoinParamsCall(
params []Param,
engPkg string,
targetMethod MethodInfo,
targetStructs map[string]StructInfo,
sourceStructs map[string]StructInfo,
) (string, error) {
return joinParamsCall(params, engPkg, targetMethod, targetStructs, sourceStructs)
}
// findSourceField finds a matching field in available source fields using multiple strategies:
// 1. Exact name match
// 2. Case-insensitive match
// 3. Snake_case match
// 4. Position-based match (fallback when structs have same field count).
// The availableSourceFields map is modified to remove matched fields.
func findSourceField(
targetField FieldInfo,
targetIdx int,
targetStruct StructInfo,
sourceStruct StructInfo,
availableSourceFields map[string]FieldInfo,
) (FieldInfo, bool) {
// Strategy 1: Exact name match
if sf, ok := availableSourceFields[targetField.Name]; ok {
return sf, true
}
// Strategy 2: Case-insensitive match
for _, sf := range availableSourceFields {
if strings.EqualFold(sf.Name, targetField.Name) {
return sf, true
}
}
// Strategy 3: Snake_case match
targetSnake := toSnakeCase(targetField.Name)
for _, sf := range availableSourceFields {
if toSnakeCase(sf.Name) == targetSnake {
return sf, true
}
}
// Strategy 4: Position-based match (fallback when structs have same field count)
// Only use position matching if the structs have the same number of fields
if len(sourceStruct.Fields) != len(targetStruct.Fields) || len(sourceStruct.Fields) == 0 {
return FieldInfo{}, false
}
// Match by position - use the field at the same index in source
if targetIdx >= len(sourceStruct.Fields) {
return FieldInfo{}, false
}
originalSourceField := sourceStruct.Fields[targetIdx]
// Check if it's still available
sf, ok := availableSourceFields[originalSourceField.Name]
if !ok {
return FieldInfo{}, false
}
// Verify types are compatible
if fieldsCompatible(sf.Type, targetField.Type) {
return sf, true
}
return FieldInfo{}, false
}
// fieldsCompatible checks if two field types are compatible for mapping.
func fieldsCompatible(sourceType, targetType string) bool {
// Normalize types for comparison
sourceBase := normalizeType(sourceType)
targetBase := normalizeType(targetType)
return sourceBase == targetBase
}
// normalizeType normalizes a type string for comparison.
func normalizeType(t string) string {
// Remove common prefixes/suffixes
t = strings.TrimPrefix(t, "[]")
t = strings.TrimPrefix(t, "*")
// Handle time types
if strings.Contains(t, "time.Time") || strings.Contains(t, "NullTime") {
return "time"
}
// Handle numeric types
switch t {
case typeInt, "int8", "int16", "int32", "int64",
"uint", "uint8", "uint16", "uint32", "uint64",
sqlNullInt32, sqlNullInt64:
return typeInt
case "float32", "float64", sqlNullFloat64:
return "float"
case typeString, sqlNullString, typeBytes:
return typeString
case typeBool, sqlNullBool:
return typeBool
}
// Remove package prefix if present
parts := strings.Split(t, ".")
if len(parts) > 1 {
return parts[len(parts)-1]
}
return t
}
func joinDomainStructParam(
param Param,
i int,
engPkg string,
targetMethod MethodInfo,
targetStructs map[string]StructInfo,
sourceStructs map[string]StructInfo,
) (string, error) {
if strings.HasPrefix(param.Type, "[]") {
return "", errUnsupportedSliceDomainStruct(param.Type)
}
targetParamType := ""
if i < len(targetMethod.Params) {
targetParamType = targetMethod.Params[i].Type
}
if targetParamType != "" {
sourceStruct := sourceStructs[param.Type]
// Target struct keys may include the package prefix (e.g., "mysqldb.GetStuckNarFilesParams")
// Try with prefix first, then without
targetStructKey := targetParamType
if engPkg != "" {
if _, ok := targetStructs[engPkg+"."+targetParamType]; ok {
targetStructKey = engPkg + "." + targetParamType
}
// Otherwise keep using targetParamType (no prefix)
}
targetStruct := targetStructs[targetStructKey]
// Create a map of available source fields to track which fields have been mapped.
availableSourceFields := make(map[string]FieldInfo, len(sourceStruct.Fields))
for _, sf := range sourceStruct.Fields {
availableSourceFields[sf.Name] = sf
}
var fields []string
for targetIdx, targetField := range targetStruct.Fields {
sourceField, found := findSourceField(targetField, targetIdx, targetStruct, sourceStruct, availableSourceFields)
if found {
conversion := generateFieldConversion(
targetField.Name,
targetField.Type,
sourceField.Type,
fmt.Sprintf("%s.%s", param.Name, sourceField.Name),
)
fields = append(fields, conversion)
// Remove the mapped field so it can't be used again.
delete(availableSourceFields, sourceField.Name)
}
}
return fmt.Sprintf("%s.%s{\n%s,\n}", engPkg, targetParamType, strings.Join(fields, ",\n")), nil
}
return fmt.Sprintf("%s.%s(%s)", engPkg, param.Type, param.Name), nil
}
func joinNonDomainParam(param Param, i int, targetMethod MethodInfo) string {
targetParamType := ""
if i < len(targetMethod.Params) {
targetParamType = targetMethod.Params[i].Type
}
if targetParamType != "" && targetParamType != param.Type {
return fmt.Sprintf("%s(%s)", targetParamType, param.Name)
}
return param.Name
}
func joinParamsCall(
params []Param,
engPkg string,
targetMethod MethodInfo,
targetStructs map[string]StructInfo,
sourceStructs map[string]StructInfo,
) (string, error) {
p := make([]string, 0, len(params))
for i, param := range params {
if isDomainStructFunc(param.Type) {
result, err := joinDomainStructParam(param, i, engPkg, targetMethod, targetStructs, sourceStructs)
if err != nil {
return "", err
}
p = append(p, result)
} else {
p = append(p, joinNonDomainParam(param, i, targetMethod))
}
}
return strings.Join(p, ", "), nil
}
func joinReturns(returns []Return) string {
r := make([]string, 0, len(returns))
for _, ret := range returns {
r = append(r, ret.Type)
}
return strings.Join(r, ", ")
}
func isSlice(retType string) bool {
return strings.HasPrefix(retType, "[]")
}
func firstReturnType(returns []Return) string {
if len(returns) > 0 {
return returns[0].Type
}
return ""
}
// isDomainStructFunc checks if type is a "Domain Struct" based on naming convention.
func isDomainStructFunc(t string) bool {
t = strings.TrimPrefix(t, "[]")
return len(t) > 0 && t[0] >= 'A' && t[0] <= 'Z' && !strings.Contains(t, ".") && t != typeQuerier
}
// isDomainStruct is used during parsing, same logic.
func isDomainStruct(t string) bool {
return isDomainStructFunc(t)
}
func zeroValue(t string) string {
if isNumeric(t) {
return "0"
}
switch t {
case typeBool:
return "false"
case typeString:
return `""`
case "error":
return zeroNil
}
if strings.HasPrefix(t, "*") || strings.HasPrefix(t, "[]") || strings.HasPrefix(t, "map[") || t == typeAny {
return zeroNil
}
if t == "sql.Result" || t == typeQuerier {
return zeroNil
}
return fmt.Sprintf("%s{}", t)
}
func isNumeric(t string) bool {
switch t {
case "int", "int8", typeInt16, typeInt32, typeInt64:
return true
case "uint", "uint8", "uint16", "uint32", "uint64":
return true
case "float32", typeFloat64, "complex64", "complex128":
return true
case typeByte, "rune":
return true
}
return false
}
func isStructType(t string) bool {
return strings.HasPrefix(t, "sql.Null")
}
func isSQLNullType(t string) bool {
return strings.HasPrefix(t, "sql.Null")
}
func getPrimitiveFromNullType(t string) string {
switch t {
case sqlNullString:
return typeString
case sqlNullInt64:
return typeInt64
case sqlNullInt32:
return typeInt32
case sqlNullInt16:
return typeInt16
case sqlNullBool:
return typeBool
case sqlNullFloat64:
return typeFloat64
case sqlNullTime:
return "time.Time"
case sqlNullByte:
return typeByte
default:
return ""
}
}
func getNullTypeFromPrimitive(t string) string {
switch t {
case typeString:
return sqlNullString
case typeInt64:
return sqlNullInt64
case typeInt32:
return sqlNullInt32
case typeInt16:
return sqlNullInt16
case typeBool:
return sqlNullBool
case typeFloat64:
return sqlNullFloat64
case "time.Time":
return sqlNullTime
case typeByte:
return sqlNullByte
default:
return ""
}
}
func getFieldNameForNullType(t string) string {
switch t {
case sqlNullString:
return "String"
case sqlNullInt64:
return "Int64"
case sqlNullInt32:
return "Int32"
case sqlNullInt16:
return "Int16"
case sqlNullBool:
return "Bool"
case sqlNullFloat64:
return "Float64"
case sqlNullTime:
return "Time"
case sqlNullByte:
return "Byte"
default:
return ""
}
}
// generateFieldConversion generates the conversion code for a field mapping.
func generateFieldConversion(targetFieldName, targetFieldType, sourceFieldType, sourceExpr string) string {
// Case 1: Types are identical - direct assignment
if sourceFieldType == targetFieldType {
return fmt.Sprintf("%s: %s", targetFieldName, sourceExpr)
}
// Case 4: Both are sql.Null* types but different
if isSQLNullType(sourceFieldType) && isSQLNullType(targetFieldType) {
sourcePrimitive := getPrimitiveFromNullType(sourceFieldType)
targetPrimitive := getPrimitiveFromNullType(targetFieldType)
if sourcePrimitive != "" && targetPrimitive != "" {
sourceFieldName := getFieldNameForNullType(sourceFieldType)
targetValueFieldName := getFieldNameForNullType(targetFieldType)
if sourcePrimitive == targetPrimitive {
return fmt.Sprintf(
"%s: %s{%s: %s.%s, Valid: %s.Valid}",
targetFieldName, targetFieldType, targetValueFieldName,
sourceExpr, sourceFieldName, sourceExpr,
)
}
return fmt.Sprintf(
"%s: %s{%s: %s(%s.%s), Valid: %s.Valid}",
targetFieldName, targetFieldType, targetValueFieldName,
targetPrimitive, sourceExpr, sourceFieldName, sourceExpr,
)
}
}
// Case 2: Converting from primitive to sql.Null* (skip interface{} — handled by Case 5b)
if isSQLNullType(targetFieldType) && sourceFieldType != typeAny {
expectedPrimitive := getPrimitiveFromNullType(targetFieldType)
if expectedPrimitive == sourceFieldType {
fieldName := getFieldNameForNullType(targetFieldType)
return fmt.Sprintf("%s: %s{%s: %s, Valid: true}", targetFieldName, targetFieldType, fieldName, sourceExpr)
} else if expectedPrimitive != "" {
fieldName := getFieldNameForNullType(targetFieldType)
return fmt.Sprintf(
"%s: %s{%s: %s(%s), Valid: true}",
targetFieldName, targetFieldType, fieldName, expectedPrimitive, sourceExpr,
)
}
}
// Case 3: Converting from sql.Null* to primitive
if isSQLNullType(sourceFieldType) {
primitive := getPrimitiveFromNullType(sourceFieldType)
if primitive == targetFieldType {
fieldName := getFieldNameForNullType(sourceFieldType)
return fmt.Sprintf("%s: %s.%s", targetFieldName, sourceExpr, fieldName)
} else if primitive != "" {
fieldName := getFieldNameForNullType(sourceFieldType)
return fmt.Sprintf("%s: %s(%s.%s)", targetFieldName, targetFieldType, sourceExpr, fieldName)
}
}
// Case 5: Struct types (non-sql.Null*) - direct assignment
if isStructType(targetFieldType) {
return fmt.Sprintf("%s: %s", targetFieldName, sourceExpr)
}
// Case 5b: interface{} source → sql.Null* target (SQLite nullable columns come as interface{})
if sourceFieldType == typeAny && isSQLNullType(targetFieldType) {
primitive := getPrimitiveFromNullType(targetFieldType)
fieldName := getFieldNameForNullType(targetFieldType)
if primitive != "" && fieldName != "" {
return fmt.Sprintf(
"%s: func() %s { if %s == nil { return %s{} }; v, ok := %s.(%s); if !ok { return %s{} };"+
" return %s{%s: v, Valid: true} }()",
targetFieldName, targetFieldType,
sourceExpr, targetFieldType,
sourceExpr, primitive,
targetFieldType, targetFieldType, fieldName,
)
}
}
// Case 6: Primitive type conversion
return fmt.Sprintf("%s: %s(%s)", targetFieldName, targetFieldType, sourceExpr)
}
func hasSliceField(s StructInfo) bool {
for _, f := range s.Fields {
if strings.HasPrefix(f.Type, "[]") && f.Type != "[]byte" {
return true
}
}
return false
}
func getSliceField(s StructInfo) FieldInfo {
for _, f := range s.Fields {
if strings.HasPrefix(f.Type, "[]") && f.Type != "[]byte" {
return f
}
}
return FieldInfo{}
}
func parseGoMod(goModPath, targetDir string) string {
data, err := os.ReadFile(goModPath)
if err != nil {
log.Fatalf("reading go.mod at %s: %v", goModPath, err)
}
moduleName := ""
for _, line := range strings.Split(string(data), "\n") {
line = strings.TrimSpace(line)
if strings.HasPrefix(line, "module ") {
moduleName = strings.TrimSpace(strings.TrimPrefix(line, "module "))
break
}
}
if moduleName == "" {
log.Fatalf("could not find module directive in %s", goModPath)
}
dir := filepath.Dir(goModPath)
relPath, err := filepath.Rel(dir, targetDir)
if err != nil {
log.Fatalf("computing relative path: %v", err)
}
if relPath == "." {
return moduleName
}
return moduleName + "/" + relPath
}
// findImportBase walks up from targetDir to find the nearest go.mod and computes
// the full import path for targetDir.
func findImportBase(targetDir string) string {
dir := targetDir
for {
goModPath := filepath.Join(dir, "go.mod")
if _, err := os.Stat(goModPath); err == nil {
return parseGoMod(goModPath, targetDir)
}
parent := filepath.Dir(dir)
if parent == dir {
log.Fatalf("no go.mod found walking up from %s", targetDir)
}
dir = parent
}
}
// detectPackageName scans .go files in dir (skipping generated_*.go) to find the package name.
func detectPackageName(dir string) string {
entries, err := os.ReadDir(dir)
if err != nil {
return filepath.Base(dir)
}
for _, e := range entries {
if e.IsDir() {
continue
}
name := e.Name()
if !strings.HasSuffix(name, ".go") {
continue
}
if strings.HasPrefix(name, "generated_") {
continue
}
if strings.HasSuffix(name, "_test.go") {
continue
}
data, err := os.ReadFile(filepath.Join(dir, name))
if err != nil {
continue
}
for _, line := range strings.Split(string(data), "\n") {
line = strings.TrimSpace(line)
if strings.HasPrefix(line, "package ") {
pkg := strings.TrimSpace(strings.TrimPrefix(line, "package "))
// Remove any trailing comment
if idx := strings.Index(pkg, " "); idx != -1 {
pkg = pkg[:idx]
}
return pkg
}
}
}
return filepath.Base(dir)
}
// Ensure getNullTypeFromPrimitive is used (referenced in templates indirectly).
var _ = getNullTypeFromPrimitive