diff --git a/pkg/generator/generator.go b/pkg/generator/generator.go index 93d0fae..967011a 100644 --- a/pkg/generator/generator.go +++ b/pkg/generator/generator.go @@ -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 = "" }