Skip to content

Commit

Permalink
Merge pull request #10 from go-gorm/lzq
Browse files Browse the repository at this point in the history
little fix
  • Loading branch information
tr1v3r authored Aug 3, 2021
2 parents f8bcc9c + 712b019 commit 7ebf3d8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
9 changes: 7 additions & 2 deletions internal/check/checkstruct.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ func (b *BaseStruct) getTableName(st interface{}) {
b.TableName = stmt.Table
}

// check if struct is exportable and if member's type is regular
// check if struct is exportable and if struct in main package and if member's type is regular
func (b *BaseStruct) check() (err error) {
if b.StructInfo.InMainPkg() {
err = fmt.Errorf("can't generated data object for struct in main package,ignored:%s", b.StructName)
log.Println(err)
return
}
if !isCapitalize(b.StructName) {
err = fmt.Errorf("ignoring non exportable struct name:%s", b.NewStructName)
err = fmt.Errorf("can't generated data object for non-exportable struct,ignore:%s", b.NewStructName)
log.Println(err)
return
}
Expand Down
2 changes: 1 addition & 1 deletion internal/parser/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func GetInterfacePath(v interface{}) (paths []*InterfacePath, err error) {
}

if strings.Split(arg.String(), ".")[0] == "main" {
_, file, _, ok := runtime.Caller(2)
_, file, _, ok := runtime.Caller(3)
if ok {
path.Files = append(path.Files, file)
}
Expand Down
4 changes: 4 additions & 0 deletions internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ func (p *Param) IsNull() bool {
return p.Package == "" && p.Type == "" && p.Name == ""
}

func (p *Param) InMainPkg() bool {
return p.Package == "main"
}

func (p *Param) IsTime() bool {
return p.Package == "time" && p.Type == "Time"
}
Expand Down

0 comments on commit 7ebf3d8

Please sign in to comment.