From 0f97ccdb91d7feda8f65a44a93b5f5881277459d Mon Sep 17 00:00:00 2001 From: "Ivan V. Dimitrov" Date: Tue, 1 Dec 2020 11:29:47 +0200 Subject: [PATCH 1/2] Exclude time package as import in the generated file --- pkg/generator/generator.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/generator/generator.go b/pkg/generator/generator.go index ff618e7..bd5414d 100644 --- a/pkg/generator/generator.go +++ b/pkg/generator/generator.go @@ -113,12 +113,18 @@ 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 { + // 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" package because it is imported by default by the + // template. + if genPkg.PkgPath == data.ValType.ImportPath || + "time" == 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 { data.KeyType.ImportName = "" data.KeyType.ImportPath = "" } From 41f5597fe88ffbb688dc07e9113104bea66781f1 Mon Sep 17 00:00:00 2001 From: "Ivan V. Dimitrov" Date: Tue, 1 Dec 2020 16:29:45 +0200 Subject: [PATCH 2/2] Include also sync --- pkg/generator/generator.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/generator/generator.go b/pkg/generator/generator.go index bd5414d..f5b734a 100644 --- a/pkg/generator/generator.go +++ b/pkg/generator/generator.go @@ -115,16 +115,18 @@ func getData(name string, keyType string, valueType string, wd string) (template // 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" package because it is imported by default by the - // template. + // the "time" and "sync" packages because they are imported by + // default by the template. if genPkg.PkgPath == data.ValType.ImportPath || - "time" == data.ValType.ImportPath { + "time" == data.ValType.ImportPath || + "sync" == data.ValType.ImportPath { data.ValType.ImportName = "" data.ValType.ImportPath = "" } if genPkg.PkgPath == data.KeyType.ImportPath || - "time" == data.KeyType.ImportPath { + "time" == data.KeyType.ImportPath || + "sync" == data.KeyType.ImportPath { data.KeyType.ImportName = "" data.KeyType.ImportPath = "" }