Skip to content

Commit

Permalink
支持结构体别名
Browse files Browse the repository at this point in the history
  • Loading branch information
Kotodian committed May 28, 2021
1 parent c66687d commit 47195e1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions examples/dao/users.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions examples/models/common/users.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package common

type Status int
type User struct {
Name string `gorm:"column:name" query:"equal,scope"`
Age int `gorm:"column:age" query:"scope"`
Company Company
Status Status `gorm:"column:status" query:"equal"`
}

type Company struct {
Expand Down
9 changes: 8 additions & 1 deletion generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,17 @@ func (g *Generator) parseFile() ([]*File, error) {
continue
}
tags := extractTag(v.Tag.Value)
typIdent := v.Type.(*ast.Ident)
var typ string
if typIdent.Obj != nil {
typ = file.pkg + "." + typIdent.Name
} else {
typ = typIdent.Name
}
if tags.Gorm(v.Names[0].Name) {
fields = append(fields, &Field{
name: v.Names[0].Name,
goType: v.Type.(*ast.Ident).Name,
goType: typ,
tags: tags,
})
}
Expand Down

0 comments on commit 47195e1

Please sign in to comment.