From bf2bdb125dfa579216659155a7f3ca7901c42cc1 Mon Sep 17 00:00:00 2001 From: Oleg Boldenkov Date: Tue, 9 Apr 2024 13:04:46 +0300 Subject: [PATCH] Exclude "sync" and "time" as duplicate imports. #55 --- pkg/generator/generator.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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 = "" }