Skip to content

Commit

Permalink
Fix bug that struct is not imported correctly when file generate anot…
Browse files Browse the repository at this point in the history
…her directory
  • Loading branch information
kanji-yomoda committed Aug 18, 2020
1 parent 1cdeb40 commit dba9518
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
52 changes: 26 additions & 26 deletions factorytpl.go

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

7 changes: 7 additions & 0 deletions generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fixtory

import (
"bytes"
"fmt"
"github.com/k-yomo/fixtory/pkg/astutil"
"go/ast"
"go/format"
Expand Down Expand Up @@ -41,11 +42,17 @@ func Generate(targetDir string, types []string, pkgName string, newWriter func()
fieldNames = append(fieldNames, field.Names[0].Name)
}
tpl := template.Must(template.New("factory").Funcs(template.FuncMap{"ToLower": strings.ToLower}).Parse(factoryTpl))
st := spec.Name.Name
if pkgName != "" {
st = fmt.Sprintf("%s.%s", walker.Pkg.Name, st)
}
params := struct {
StructName string
Struct string
FieldNames []string
}{
StructName: spec.Name.Name,
Struct: st,
FieldNames: fieldNames,
}
if err := tpl.Execute(body, params); err != nil {
Expand Down

0 comments on commit dba9518

Please sign in to comment.