From a6b65d30c745e951bd2243b02f00bcbf21e6f3f6 Mon Sep 17 00:00:00 2001 From: finelog Date: Wed, 2 Dec 2020 21:03:38 +0800 Subject: [PATCH] prevent panic when struct with unexport field --- tags/parser.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tags/parser.go b/tags/parser.go index add30a13..a301d124 100644 --- a/tags/parser.go +++ b/tags/parser.go @@ -253,7 +253,7 @@ func (parser *Parser) Parse(v reflect.Value) (*schemas.Table, error) { addIndex(indexName, table, col, indexType) } } - } else { + } else if fieldValue.CanSet() { var sqlType schemas.SQLType if fieldValue.CanAddr() { if _, ok := fieldValue.Addr().Interface().(convert.Conversion); ok { @@ -272,6 +272,8 @@ func (parser *Parser) Parse(v reflect.Value) (*schemas.Table, error) { if fieldType.Kind() == reflect.Int64 && (strings.ToUpper(col.FieldName) == "ID" || strings.HasSuffix(strings.ToUpper(col.FieldName), ".ID")) { idFieldColName = col.Name } + } else { + continue } if col.IsAutoIncrement { col.Nullable = false