Skip to content

Commit bf2bdb1

Browse files
committed
Exclude "sync" and "time" as duplicate imports. vektah#55
1 parent 557c25d commit bf2bdb1

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

pkg/generator/generator.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,21 @@ func getData(name string, keyType string, valueType string, wd string) (template
113113
return templateData{}, fmt.Errorf("key type: %s", err.Error())
114114
}
115115

116-
// if we are inside the same package as the type we don't need an import and can refer directly to the type
117-
if genPkg.PkgPath == data.ValType.ImportPath {
116+
// See https://github.com/vektah/dataloaden/pull/55
117+
// If we are inside the same package as the type we don't need
118+
// an import and can refer directly to the type. Also exclude
119+
// the "time" and "sync" packages because they are imported by
120+
// default by the template.
121+
if genPkg.PkgPath == data.ValType.ImportPath ||
122+
"time" == data.ValType.ImportPath ||
123+
"sync" == data.ValType.ImportPath {
118124
data.ValType.ImportName = ""
119125
data.ValType.ImportPath = ""
120126
}
121-
if genPkg.PkgPath == data.KeyType.ImportPath {
127+
128+
if genPkg.PkgPath == data.KeyType.ImportPath ||
129+
"time" == data.KeyType.ImportPath ||
130+
"sync" == data.KeyType.ImportPath {
122131
data.KeyType.ImportName = ""
123132
data.KeyType.ImportPath = ""
124133
}

0 commit comments

Comments
 (0)