improve code

This commit is contained in:
Lunny Xiao 2021-06-28 00:26:29 +08:00
parent 940afb2af3
commit 4a4f4300fe
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
1 changed files with 11 additions and 11 deletions

View File

@ -246,12 +246,12 @@ func (parser *Parser) parseField(table *schemas.Table, field reflect.StructField
tag = field.Tag
ormTagStr = strings.TrimSpace(tag.Get(parser.identifier))
)
if ormTagStr == "" {
return parser.parseFieldWithNoTag(field, fieldValue)
}
if ormTagStr == "-" {
return nil, ErrIgnoreField
}
if ormTagStr == "" {
return parser.parseFieldWithNoTag(field, fieldValue)
}
tags, err := splitTag(ormTagStr)
if err != nil {
return nil, err
@ -259,6 +259,13 @@ func (parser *Parser) parseField(table *schemas.Table, field reflect.StructField
return parser.parseFieldWithTags(table, field, fieldValue, tags)
}
func isNotTitle(n string) bool {
for _, c := range n {
return unicode.IsLower(c)
}
return true
}
// Parse parses a struct as a table information
func (parser *Parser) Parse(v reflect.Value) (*schemas.Table, error) {
t := v.Type()
@ -275,14 +282,7 @@ func (parser *Parser) Parse(v reflect.Value) (*schemas.Table, error) {
table.Name = names.GetTableName(parser.tableMapper, v)
for i := 0; i < t.NumField(); i++ {
var isUnexportField bool
for _, c := range t.Field(i).Name {
if unicode.IsLower(c) {
isUnexportField = true
}
break
}
if isUnexportField {
if isNotTitle(t.Field(i).Name) {
continue
}