Skip to content

Commit 792c88a

Browse files
authored
feat: Ignore specific field types (#163)
#157 changed the behavior of printing a log message on unsupported types (like `interface`) to failing. ~~I'm not sure that's what we want as now the consumer has to skip all the interface fields to make code gen work.~~ ~~I kept the failure on custom type transformer as I believe that should be indeed a failure to generate.~~ Changed the code to explicitly specific types ---
1 parent 8aff19a commit 792c88a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

codegen/table.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,21 @@ func (t *TableDefinition) getUnwrappedFields(field reflect.StructField) []reflec
7373
return fields
7474
}
7575

76+
func isTypeIgnored(t reflect.Type) bool {
77+
switch t.Kind() {
78+
case reflect.Interface, reflect.Func, reflect.Chan, reflect.UnsafePointer:
79+
return true
80+
default:
81+
return false
82+
}
83+
}
84+
7685
func (t *TableDefinition) ignoreField(field reflect.StructField) bool {
7786
switch {
7887
case len(field.Name) == 0,
7988
slices.Contains(t.skipFields, field.Name),
80-
!field.IsExported():
89+
!field.IsExported(),
90+
isTypeIgnored(field.Type):
8191
return true
8292
default:
8393
return false

codegen/table_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type testStruct struct {
3333
JSONTAG *string `json:"json_tag"`
3434
SKIPJSONTAG *string `json:"-"`
3535
NOJSONTAG *string
36+
InterfaceCol interface{}
3637

3738
*embeddedStruct
3839
}

0 commit comments

Comments
 (0)