Skip to content

Commit

Permalink
Merge pull request #1 from olegbolden/duplicates_patch
Browse files Browse the repository at this point in the history
Exclude "sync" and "time" as duplicate imports. vektah#55
  • Loading branch information
olegbolden authored Apr 9, 2024
2 parents 557c25d + bf2bdb1 commit 3b1defb
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pkg/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,21 @@ func getData(name string, keyType string, valueType string, wd string) (template
return templateData{}, fmt.Errorf("key type: %s", err.Error())
}

// if we are inside the same package as the type we don't need an import and can refer directly to the type
if genPkg.PkgPath == data.ValType.ImportPath {
// See https://github.com/vektah/dataloaden/pull/55
// If we are inside the same package as the type we don't need
// an import and can refer directly to the type. Also exclude
// the "time" and "sync" packages because they are imported by
// default by the template.
if genPkg.PkgPath == data.ValType.ImportPath ||
"time" == data.ValType.ImportPath ||
"sync" == data.ValType.ImportPath {
data.ValType.ImportName = ""
data.ValType.ImportPath = ""
}
if genPkg.PkgPath == data.KeyType.ImportPath {

if genPkg.PkgPath == data.KeyType.ImportPath ||
"time" == data.KeyType.ImportPath ||
"sync" == data.KeyType.ImportPath {
data.KeyType.ImportName = ""
data.KeyType.ImportPath = ""
}
Expand Down

0 comments on commit 3b1defb

Please sign in to comment.